when package:universum

Conditional execution of Applicative expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.
Monadic version of when.
>>> whenM (pure False) $ putTextLn "No text :("

>>> whenM (pure True)  $ putTextLn "Yes text :)"
Yes text :)

>>> whenM (Just True) (pure ())
Just ()

>>> whenM (Just False) (pure ())
Just ()

>>> whenM Nothing (pure ())
Nothing
Performs given action over NonEmpty list if given list is non empty.
>>> whenNotNull [] $ \(b :| _) -> print (not b)

>>> whenNotNull [False,True] $ \(b :| _) -> print (not b)
True
Monadic version of whenNotNull.
Applies given action to Either content if Left is given.
Monadic version of whenLeft.
Applies given action to Either content if Right is given.
Monadic version of whenRight.
Specialized version of for_ for Maybe. It's used for code readability. Also helps to avoid space leaks: Foldable.mapM_ space leak.
>>> whenJust Nothing $ \b -> print (not b)

>>> whenJust (Just True) $ \b -> print (not b)
False
Monadic version of whenJust.
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]
Monadic version of whenNothing.
Monadic version of whenNothingM_.
Performs default Applicative action if Nothing is given. Do nothing for Just. Convenient for discarding Just content.
>>> whenNothing_ Nothing $ putTextLn "Nothing!"
Nothing!

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