module Data.Maybe.HT where
import Data.Maybe (fromMaybe, )
import Control.Monad (msum, )
{-# INLINE toMaybe #-}
toMaybe :: Bool -> a -> Maybe a
toMaybe :: Bool -> a -> Maybe a
toMaybe Bool
False a
_ = Maybe a
forall a. Maybe a
Nothing
toMaybe Bool
True a
x = a -> Maybe a
forall a. a -> Maybe a
Just a
x
infixl 6 ?->
(?->) :: Maybe a -> (a -> b) -> Maybe b
?-> :: Maybe a -> (a -> b) -> Maybe b
(?->) = ((a -> b) -> Maybe a -> Maybe b) -> Maybe a -> (a -> b) -> Maybe b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
alternatives :: a -> [Maybe a] -> a
alternatives :: a -> [Maybe a] -> a
alternatives a
deflt = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
deflt (Maybe a -> a) -> ([Maybe a] -> Maybe a) -> [Maybe a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe a] -> Maybe a
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum