Add choose utilties to util

This commit is contained in:
Nathan McCarty 2025-01-14 16:02:39 -05:00
parent b0e7c1aa91
commit a83cef8360

View file

@ -155,3 +155,28 @@ export
trace : Has Logger fs => Lazy String -> Eff fs ()
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
```