| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Maybe.Justify
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!"