{-# LANGUAGE ExplicitForAll #-} -- | Helpful extra functions concerning Maybe module Hextra.Maybe where fromNothing :: forall a. a -> Maybe a -> a fromNothing :: a -> Maybe a -> a fromNothing a x Maybe a Nothing = a x fromNothing a _ (Just a y) = a y -- ^ Extracts a value from a Maybe value, -- uses replacement value in case of Nothing. catchNothing :: forall a b. b -> (a -> Maybe b) -> a -> b catchNothing :: b -> (a -> Maybe b) -> a -> b catchNothing b x = (b -> Maybe b -> b forall a. a -> Maybe a -> a fromNothing b x (Maybe b -> b) -> (a -> Maybe b) -> a -> b forall b c a. (b -> c) -> (a -> b) -> a -> c .) -- ^ Composes fromNothing with a function. -- Useful to make a function that relies on another function that returns a Maybe