Safe Haskell | None |
---|---|

Language | Haskell2010 |

- class Applicative f => Alternative f where
- (<|>) :: Alternative f => forall a. f a -> f a -> f a
- empty :: Alternative f => forall a. f a
- some :: Alternative f => forall a. f a -> f [a]
- many :: Alternative f => forall a. f a -> f [a]
- optional :: Alternative f => f a -> f (Maybe a)
- afilter :: (Monad m, Alternative m) => (a -> Bool) -> m a -> m a
- asum :: (Foldable t, Alternative f) => t (f a) -> f a
- guard :: Alternative f => Bool -> f ()
- ensure :: Alternative f => (a -> Bool) -> a -> f a
- eitherA :: Alternative f => f a -> f b -> f (Either a b)
- toAlt :: (Alternative f, Foldable t) => t a -> f a
- mapAlt :: (Monad m, Alternative m, Foldable f) => (a -> f b) -> m a -> m b

# Alternative class

class Applicative f => Alternative f where #

A monoid on applicative functors.

If defined, `some`

and `many`

should be the least solutions
of the equations:

The identity of `<|>`

(<|>) :: f a -> f a -> f a infixl 3 #

An associative binary operation

One or more.

Zero or more.

Alternative [] | |

Alternative Maybe | |

Alternative IO | |

Alternative U1 | |

Alternative Option | |

Alternative Seq | |

Alternative f => Alternative (Rec1 f) | |

MonadPlus m => Alternative (WrappedMonad m) | |

ArrowPlus a => Alternative (ArrowMonad a) | |

Alternative (Proxy *) | |

(Alternative f, Alternative g) => Alternative ((:*:) f g) | |

(Alternative f, Applicative g) => Alternative ((:.:) f g) | |

(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | |

Alternative f => Alternative (Alt * f) | |

(Functor m, Monad m, Error e) => Alternative (ErrorT e m) | |

(Functor m, MonadPlus m) => Alternative (StateT s m) | |

Alternative f => Alternative (M1 i c f) | |

(Alternative f, Alternative g) => Alternative (Product * f g) | |

(Alternative f, Applicative g) => Alternative (Compose * * f g) | |

(<|>) :: Alternative f => forall a. f a -> f a -> f a #

An associative binary operation

empty :: Alternative f => forall a. f a #

The identity of `<|>`

some :: Alternative f => forall a. f a -> f [a] #

One or more.

many :: Alternative f => forall a. f a -> f [a] #

Zero or more.

# Utility functions

optional :: Alternative f => f a -> f (Maybe a) #

One or none.

afilter :: (Monad m, Alternative m) => (a -> Bool) -> m a -> m a Source #

A generalized version of `filter`

, which works on anything which is
both a `Monad`

and `Alternative`

.

\(Blind p) xs -> filter p xs === afilter p xs

asum :: (Foldable t, Alternative f) => t (f a) -> f a #

The sum of a collection of actions, generalizing `concat`

.

ensure :: Alternative f => (a -> Bool) -> a -> f a Source #

`ensure`

allows you to attach a condition to something

eitherA :: Alternative f => f a -> f b -> f (Either a b) Source #

`eitherA`

is especially useful for parsers.

toAlt :: (Alternative f, Foldable t) => t a -> f a Source #

Convert any `Foldable`

to an `Alternative`