monad-extras-0.3.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 ().

discard :: Monad m => a -> m ()Source

Discards a value

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.

label :: ContT r m (ContT r m a)Source

Return a continuation that one can jump back to within ContT.

>>> flip runContT return $ do { k <- label; ...; k }

io :: MonadIO m => IO a -> m aSource

Short-hand for liftIO.

liftMaybe :: MonadPlus m => Maybe a -> m aSource

Lift a Maybe value into the MaybeT monad transformer.