safe-foldable-0.1.0.0: Safe wrappers for null-partial Foldable operations

Safe HaskellSafe
LanguageHaskell2010

Data.Foldable.Safe

Description

Safe wrappers for null-partial Foldable operations

>>> minimum []
*** Exception: Prelude.minimum: empty list
>>> minimum [3,1,2]
1
>>> defaulting 0 minimum []
0
>>> defaulting 0 minimum [3,1,2]
1
>>> mayhap minimum []
Nothing
>>> mayhap minimum [3,1,2]
Just 1

Synopsis

Documentation

defaulting :: Foldable f => b -> (f a -> b) -> f a -> b Source #

Apply a function to Foldable data if it is not null. Otherwise, return a default value.

mayhap :: Foldable f => (f a -> b) -> f a -> Maybe b Source #

Apply a function to Foldable data if it is not null, wrapping the result in Just. Otherwise, return Nothing.