maybe-justify-0.1.0.0: Simple higher order function for Maybe

Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Maybe.Justify

Synopsis

Documentation

justify :: (a -> b) -> (a -> Bool) -> a -> Maybe b Source

Control flow has always been obtuse, and justify makes simple if-then-else statements simple one liners.

Examples

Realistically this is very ineffecient, but interesting to see

>>> justify fromJust isJust (Maybe True) == id (Maybe True)
True

A somewhat more realistic example where you generate a maybe with control flow then make a change to the returned value with a provided default.

>>> maybe "Default" (<> "!") (justify (<> " World") (/= mempty) "Hello")
"Hello World!"