Just package:universum

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.
The isJust function returns True iff its argument is of the form Just _.

Examples

Basic usage:
>>> isJust (Just 3)
True
>>> isJust (Just ())
True
>>> isJust Nothing
False
Only the outer constructor is taken into consideration:
>>> isJust (Just Nothing)
True
The fromJust function extracts the element out of a Just and throws an error if its argument is Nothing.

Examples

Basic usage:
>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing
...
WARNING: This function is partial. You can use case-matching instead.