# Module Maybe

Library with some useful functions on the Maybe datatype.

Author: Frank Huch, Bernd Brassel, Bjoern Peemoeller

Version: October 2014

## Summary of exported operations:

 isJust :: Maybe a -> Bool    Return True iff the argument is of the form Just _. isNothing :: Maybe a -> Bool    Return True iff the argument is of the form Nothing. fromJust :: Maybe a -> a    Extract the argument from the Just constructor and throw an error if the argument is Nothing. fromMaybe :: a -> Maybe a -> a    Extract the argument from the Just constructor or return the provided default value if the argument is Nothing. listToMaybe :: [a] -> Maybe a    Return Nothing on an empty list or Just x where x is the first list element. maybeToList :: Maybe a -> [a]    Return an empty list for Nothing or a singleton list for Just x. catMaybes :: [Maybe a] -> [a]    Return the list of all Just values. mapMaybe :: (a -> Maybe b) -> [a] -> [b]    Apply a function which may throw out elements using the Nothing constructor to a list of elements. (>>-) :: Maybe a -> (a -> Maybe b) -> Maybe b    Monadic bind for Maybe. sequenceMaybe :: [Maybe a] -> Maybe [a]    Monadic sequence for Maybe. mapMMaybe :: (a -> Maybe b) -> [a] -> Maybe [b]    Monadic map for Maybe. mplus :: Maybe a -> Maybe a -> Maybe a    Combine two Maybes, returning the first Just value, if any.

## Exported operations:

 isJust :: Maybe a -> Bool    Return True iff the argument is of the form Just _. Further infos: solution complete, i.e., able to compute all solutions
 isNothing :: Maybe a -> Bool    Return True iff the argument is of the form Nothing. Further infos: solution complete, i.e., able to compute all solutions
 fromJust :: Maybe a -> a    Extract the argument from the Just constructor and throw an error if the argument is Nothing.
 fromMaybe :: a -> Maybe a -> a    Extract the argument from the Just constructor or return the provided default value if the argument is Nothing. Further infos: solution complete, i.e., able to compute all solutions
 listToMaybe :: [a] -> Maybe a    Return Nothing on an empty list or Just x where x is the first list element. Further infos: solution complete, i.e., able to compute all solutions
 maybeToList :: Maybe a -> [a]    Return an empty list for Nothing or a singleton list for Just x. Further infos: solution complete, i.e., able to compute all solutions
 catMaybes :: [Maybe a] -> [a]    Return the list of all Just values.
 mapMaybe :: (a -> Maybe b) -> [a] -> [b]    Apply a function which may throw out elements using the Nothing constructor to a list of elements.
 (>>-) :: Maybe a -> (a -> Maybe b) -> Maybe b    Monadic bind for Maybe. Maybe can be interpreted as a monad where Nothing is interpreted as the error case by this monadic binding. Example call: (maybeValue >>- f) Parameters: maybeValue : Nothing or Just x f : function to be applied to x Returns: Nothing if maybeValue is Nothing, otherwise f is applied to x Further infos: defined as left-associative infix operator with precedence 1
 sequenceMaybe :: [Maybe a] -> Maybe [a]    Monadic sequence for Maybe.
 mapMMaybe :: (a -> Maybe b) -> [a] -> Maybe [b]    Monadic map for Maybe.
 mplus :: Maybe a -> Maybe a -> Maybe a    Combine two Maybes, returning the first Just value, if any. Further infos: solution complete, i.e., able to compute all solutions