monad-extras-0.1.0.0: Extra utility functions for working with monads

Safe HaskellSafe-Inferred

Control.Monad.Extra

Synopsis

Documentation

skip :: Monad m => m ()Source

Synonym for return ().

obvious :: Applicative f => f ()Source

Synonym for pure ().

bind :: Monad m => m a -> (a -> m b) -> m bSource

Function name for >>=, as fmap is to <$>.

om :: Monad m => (a -> b -> m c) -> m a -> b -> m cSource

Combinator for working with monadic values:

>>> om when (return True) $ print "Hello"
"Hello"
>>> return True >>= flip when (print "Hello")
"Hello"
>>> om forM_ (return [True]) print
True
>>> flip forM_ print =<< return [True]
True
>>> mapM_ print =<< return [True]
True

Subsumes the need for individual functions for whenM, unlessM, etc.

nom :: Monad m => (a -> b -> m c) -> a -> m b -> m cSource

Variant of om which changes the roles of the 2nd and 3rd arguments.

>>> nom mapM_ print $ return [True]
True
>>> mapM_ print =<< return [True]
True

doCallCC :: Monad m => ((r -> ContT r m b) -> ContT r m r) -> m rSource

Convenience function if all you want to use is callCC.