| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Control.Coapplicative
Synopsis
- type Applicative' f = (Apply f, Applicative f)
- class Coapply f => Coapplicative f where
- copure :: f a -> a
- class Functor f => Coapply f where
- apply :: Apply f => (f a, f b) -> f (a, b)
- select :: Functor f => f (a, b) -> (f a, f b)
- coselect :: Functor f => (f a + f b) -> f (a + b)
- coeval :: Coapply f => f (a + b) -> f (a + b)
- type Select f = (Coapply f, Apply f)
- eitherS :: Select f => f (a + b) -> f (a -> c) -> f (b -> c) -> f c
- branch :: Select f => f Bool -> f a -> f a -> f a
- bindBool :: Select f => f Bool -> (Bool -> f a) -> f a
- type Selective f = (Coapply f, Applicative' f)
- apS :: Selective f => f (a -> b) -> f a -> f b
- (<*?) :: Selective f => f (a + b) -> f (a -> b) -> f b
- eliminate :: Eq a => Selective f => a -> f b -> f (a + b) -> f (a + b)
- whenS :: Selective f => f Bool -> f () -> f ()
- whileS :: Selective f => f Bool -> f ()
- fromMaybeS :: Selective f => f a -> f (Maybe a) -> f a
- untilRight :: Monoid a => Selective f => f (a + b) -> f (a, b)
- (<||>) :: Selective f => f Bool -> f Bool -> f Bool
- (<&&>) :: Selective f => f Bool -> f Bool -> f Bool
- anyS :: Selective f => (a -> f Bool) -> [a] -> f Bool
- allS :: Selective f => (a -> f Bool) -> [a] -> f Bool
- foldS :: (Selective f, Foldable t, Monoid b) => t (f (a + b)) -> f (a + b)
- orElse :: Semigroup a => Selective f => f (a + b) -> f (a + b) -> f (a + b)
- andAlso :: Semigroup b => Selective f => f (a + b) -> f (a + b) -> f (a + b)
- appendl :: Semigroup a => a -> (a + b) -> a + b
Documentation
type Applicative' f = (Apply f, Applicative f) Source #
Coapplicative
class Coapply f => Coapplicative f where Source #
Instances
| Coapplicative Identity Source # | |
Defined in Control.Coapplicative | |
| Coapplicative NonEmpty Source # | |
Defined in Control.Coapplicative | |
| Coapplicative ((,) r) Source # | |
Defined in Control.Coapplicative | |
| Coapplicative (Tagged k) Source # | |
Defined in Control.Coapplicative | |
| Monoid r => Coapplicative ((->) r) Source # | |
Defined in Control.Coapplicative | |
| (Coapplicative f, Coapplicative g) => Coapplicative (Compose f g) Source # | |
Defined in Control.Coapplicative | |
Coapply
coeval :: Coapply f => f (a + b) -> f (a + b) Source #
Evaluate a coapplicative expression, exiting on the first Left if it exists.
>>>coeval $ Left "foo" :| [Right "bar"]Left "foo" :| []>>>coeval $ Right "foo" :| [Right "bar"]Right "foo" :| [Right "bar"]
Select
branch :: Select f => f Bool -> f a -> f a -> f a Source #
Branch on a boolean value, skipping unnecessary effects.
>>>head $ branch (True :| []) (print "foo" :| []) (print "bar" :| [])"foo"
Selective
type Selective f = (Coapply f, Applicative' f) Source #
apS :: Selective f => f (a -> b) -> f a -> f b Source #
Recover the application operator <*> from <*?. Rigid selective
functors satisfy the law <*> = apS and furthermore, the resulting
applicative functor satisfies all laws of Applicative:
Identity:
pure id <*> v = v
Homomorphism:
pure f <*> pure x = pure (f x)
Interchange:
u <*> pure y = pure ($y) <*> u
Composition:
(.) <$> u <*> v <*> w = u <*> (v <*> w)
eliminate :: Eq a => Selective f => a -> f b -> f (a + b) -> f (a + b) Source #
Eliminate the a from f (a + b) and replace with the provided f b.
>>>eliminate 1.0 ["foo","bar"] [Left 1.0] :: [Float + String][Right "foo",Right "bar"]>>>eliminate 1.0 ["foo","bar"] [Left 3.4] :: [Float + String][Left 3.4]
whileS :: Selective f => f Bool -> f () Source #
Keep checking an effectful condition while it holds.
untilRight :: Monoid a => Selective f => f (a + b) -> f (a, b) Source #
Keep running an effectful computation until it returns a Right value,
collecting the Left's using a supplied Monoid instance.
anyS :: Selective f => (a -> f Bool) -> [a] -> f Bool Source #
A lifted version of any. Retains the short-circuiting behaviour.
allS :: Selective f => (a -> f Bool) -> [a] -> f Bool Source #
A lifted version of all. Retains the short-circuiting behaviour.
foldS :: (Selective f, Foldable t, Monoid b) => t (f (a + b)) -> f (a + b) Source #
Generalised folding with the short-circuiting behaviour.
orElse :: Semigroup a => Selective f => f (a + b) -> f (a + b) -> f (a + b) Source #
Return the first Right value. If both are Left's, accumulate errors.
andAlso :: Semigroup b => Selective f => f (a + b) -> f (a + b) -> f (a + b) Source #
Accumulate the Right values, or return the first Left.
>>>andAlso [Right "foo", Right "bar", Right "baz"] [Right "!"][Right "foo!",Right "bar!",Right "baz!"]>>>andAlso [Right "foo", Right "bar", Left 'e'] [Right "!"][Right "foo!",Right "bar!"]>>>andAlso [Right "foo", Right "bar", Left 'e'] [Left 'f'][Left 'f',Left 'f']