coapplicative
Safe HaskellSafe
LanguageHaskell2010

Control.Coapplicative

Synopsis

Documentation

Coapplicative

class Coapply f => Coapplicative f where Source #

Methods

copure :: f a -> a Source #

Instances

Instances details
Coapplicative Identity Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: Identity a -> a Source #

Coapplicative NonEmpty Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: NonEmpty a -> a Source #

Coapplicative ((,) r) Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: (r, a) -> a Source #

Coapplicative (Tagged k) Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: Tagged k a -> a Source #

Monoid r => Coapplicative ((->) r) Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: (r -> a) -> a Source #

(Coapplicative f, Coapplicative g) => Coapplicative (Compose f g) Source # 
Instance details

Defined in Control.Coapplicative

Methods

copure :: Compose f g a -> a Source #

Coapply

class Functor f => Coapply f where Source #

Methods

coapply :: f (a + b) -> f a + f b Source #

Instances

Instances details
Coapply Identity Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: Identity (a + b) -> Identity a + Identity b Source #

Coapply NonEmpty Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: NonEmpty (a + b) -> NonEmpty a + NonEmpty b Source #

Coapply Maybe Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: Maybe (a + b) -> Maybe a + Maybe b Source #

Coapply List Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: [a + b] -> [a] + [b] Source #

Coapply ((,) r) Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: (r, a + b) -> (r, a) + (r, b) Source #

Coapply (Const r :: Type -> Type) Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: Const r (a + b) -> Const r a + Const r b Source #

Coapply (Tagged k) Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: Tagged k (a + b) -> Tagged k a + Tagged k b Source #

Monoid r => Coapply ((->) r) Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: (r -> (a + b)) -> (r -> a) + (r -> b) Source #

(Coapply f, Coapply g) => Coapply (Compose f g) Source # 
Instance details

Defined in Data.Functor.Coapply

Methods

coapply :: Compose f g (a + b) -> Compose f g a + Compose f g b Source #

apply :: Apply f => (f a, f b) -> f (a, b) Source #

select :: Functor f => f (a, b) -> (f a, f b) Source #

coselect :: Functor f => (f a + f b) -> f (a + b) Source #

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

type Select f = (Coapply f, Apply f) Source #

eitherS :: Select f => f (a + b) -> f (a -> c) -> f (b -> c) -> f c Source #

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"

bindBool :: Select f => f Bool -> (Bool -> f a) -> f a Source #

Selective

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)

(<*?) :: Selective f => f (a + b) -> f (a -> b) -> f b infixl 4 Source #

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]

whenS :: Selective f => f Bool -> f () -> f () Source #

Conditionally perform an effect.

whileS :: Selective f => f Bool -> f () Source #

Keep checking an effectful condition while it holds.

fromMaybeS :: Selective f => f a -> f (Maybe a) -> f a Source #

A lifted version of fromMaybe.

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.

(<||>) :: Selective f => f Bool -> f Bool -> f Bool Source #

A lifted version of lazy Boolean OR.

(<&&>) :: Selective f => f Bool -> f Bool -> f Bool Source #

A lifted version of lazy Boolean AND.

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']

appendl :: Semigroup a => a -> (a + b) -> a + b Source #

Append two semigroup values or return the Right one.