when package:extra

Perform some operation on Just, given the field inside the Just. This is a specialized for_.
whenJust Nothing  print == pure ()
whenJust (Just 1) print == print 1
Like whenJust, but where the test can be monadic.
Like when, but where the test can be monadic.
Like when, but return either Nothing if the predicate was False, or Just with the result of the computation.
whenMaybe True  (print 1) == fmap Just (print 1)
whenMaybe False (print 1) == pure Nothing
Like whenMaybe, but where the test can be monadic.
Like when, but operating on a Monoid. If the first argument is True returns the second, otherwise returns mempty.
mwhen True  "test" == "test"
mwhen False "test" == ""