module Prelate.Data.Maybe where

-- |Return 'Just' if the condition is 'True'.
justIf ::
  Bool ->
  a ->
  Maybe a
justIf :: forall a. Bool -> a -> Maybe a
justIf Bool
cond a
a =
  if Bool
cond then a -> Maybe a
forall a. a -> Maybe a
Just a
a else Maybe a
forall a. Maybe a
Nothing
{-# inline justIf #-}

-- |Version of 'maybe' that takes an action as fallback.
fromMaybeA ::
  Applicative m =>
  m a ->
  Maybe a ->
  m a
fromMaybeA :: forall (m :: * -> *) a. Applicative m => m a -> Maybe a -> m a
fromMaybeA m a
fallback =
  m a -> (a -> m a) -> Maybe a -> m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe m a
fallback a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# inline fromMaybeA #-}