universum-0.4.2: Custom prelude used in Serokell

Safe HaskellSafe
LanguageHaskell2010

Monad.Maybe

Description

Utility functions to work with Maybe data type as monad.

Synopsis

Documentation

whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f () Source #

Specialized version of for_ for Maybe. It's used for code readability. Also helps to avoid space leaks: Foldable.mapM_ space leak.

whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m () Source #

Monadic version of whenJust.

whenNothing :: Applicative f => Maybe a -> f a -> f a Source #

Performs default Applicative action if Nothing is given. Otherwise returns content of Just pured to Applicative.

>>> whenNothing Nothing [True, False]
[True,False]
>>> whenNothing (Just True) [True, False]
[True]

whenNothing_ :: Applicative f => Maybe a -> f () -> f () Source #

Performs default Applicative action if Nothing is given. Do nothing for Just. Convenient for discarding Just content.

>>> whenNothing_ Nothing $ putText "Nothing!"
Nothing!
>>> whenNothing_ (Just True) $ putText "Nothing!"

whenNothingM :: Monad m => m (Maybe a) -> m a -> m a Source #

Monadic version of whenNothing.

whenNothingM_ :: Monad m => m (Maybe a) -> m () -> m () Source #

Monadic version of whenNothingM_.