mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-11-14 13:56:59 +03:00
Add "choice"
This is called asum in Haskell. I think it's appropriate for the Prelude because I've defined it myself on a number of occasions.
This commit is contained in:
parent
030da056bc
commit
d76b58360e
@ -5,6 +5,7 @@ import Builtins
|
||||
import Prelude.Basics
|
||||
import Prelude.Bool
|
||||
import Prelude.Classes
|
||||
import Prelude.Foldable
|
||||
import Prelude.Functor
|
||||
|
||||
---- Applicative functors/Idioms
|
||||
@ -48,3 +49,9 @@ guard a = if a then pure () else empty
|
||||
when : Applicative f => Bool -> Lazy (f ()) -> f ()
|
||||
when True f = Force f
|
||||
when False f = pure ()
|
||||
|
||||
||| Fold using Alternative
|
||||
|||
|
||||
||| This is called `asum` in Haskell.
|
||||
choice : (Foldable t, Alternative f) => t (f a) -> f a
|
||||
choice x = foldr (<|>) empty x
|
||||
|
Loading…
Reference in New Issue
Block a user