Add choose utilties to util
This commit is contained in:
parent
b0e7c1aa91
commit
a83cef8360
|
@ -155,3 +155,28 @@ export
|
||||||
trace : Has Logger fs => Lazy String -> Eff fs ()
|
trace : Has Logger fs => Lazy String -> Eff fs ()
|
||||||
trace x = send $ Log Trace x
|
trace x = send $ Log Trace x
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Choose
|
||||||
|
|
||||||
|
Lifts any foldable data structure into the Choose effect, enabling the style of
|
||||||
|
nondeterministic programming from the list monad
|
||||||
|
|
||||||
|
```idris
|
||||||
|
export
|
||||||
|
oneOf : Has (Choose) fs => Foldable f =>
|
||||||
|
f a -> Eff fs a
|
||||||
|
oneOf x = foldl oneOf' empty x
|
||||||
|
where
|
||||||
|
oneOf' : Eff fs a -> a -> Eff fs a
|
||||||
|
oneOf' acc val = pure val `alt` acc
|
||||||
|
```
|
||||||
|
|
||||||
|
Lifts any foldable of effectful computations into the Choose effect much the
|
||||||
|
same as `oneOf`
|
||||||
|
|
||||||
|
```idris
|
||||||
|
export
|
||||||
|
oneOfM : Has (Choose) fs => Foldable f =>
|
||||||
|
f (Eff fs a) -> Eff fs a
|
||||||
|
oneOfM x = foldl alt empty x
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue