-- |
-- Module      : OAlg.Data.Maybe
-- Description : maybe predicate
-- Copyright   : (c) Erich Gut
-- License     : BSD3
-- Maintainer  : zerich.gut@gmail.com
--
-- Maybe.
module OAlg.Data.Maybe
  ( module M
  , just
  , exstJust
  )
  where

import Data.Maybe as M

--------------------------------------------------------------------------------
-- exstJust -

-- | gets all the 'Just's - if there are any.
exstJust :: [Maybe v] -> Maybe [v]
exstJust :: forall v. [Maybe v] -> Maybe [v]
exstJust [Maybe v]
mvs = case forall a. [Maybe a] -> [a]
catMaybes [Maybe v]
mvs of
  [] -> forall a. Maybe a
Nothing
  [v]
vs -> forall a. a -> Maybe a
Just [v]
vs

--------------------------------------------------------------------------------
-- jsut -

-- | @just p a '==' 'Just' a@ if and only if @p a@.
just :: (a -> Bool) -> a -> Maybe a
just :: forall a. (a -> Bool) -> a -> Maybe a
just a -> Bool
p a
a = if a -> Bool
p a
a then forall a. a -> Maybe a
Just a
a else forall a. Maybe a
Nothing