{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
module PlutusTx.Maybe (Maybe(..), isJust, isNothing, maybe, fromMaybe, mapMaybe) where
import PlutusTx.Base (id)
import PlutusTx.Bool
import PlutusTx.List (foldr)
import Prelude (Maybe (..))
isJust :: Maybe a -> Bool
isJust :: forall a. Maybe a -> Bool
isJust Maybe a
m = case Maybe a
m of { Just a
_ -> Bool
True; Maybe a
_ -> Bool
False; }
{-# INLINABLE isJust #-}
isNothing :: Maybe a -> Bool
isNothing :: forall a. Maybe a -> Bool
isNothing Maybe a
m = case Maybe a
m of { Just a
_ -> Bool
False; Maybe a
_ -> Bool
True; }
{-# INLINABLE isNothing #-}
maybe :: b -> (a -> b) -> Maybe a -> b
maybe :: forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
b a -> b
f Maybe a
m = case Maybe a
m of
Maybe a
Nothing -> b
b
Just a
a -> a -> b
f a
a
{-# INLINABLE maybe #-}
fromMaybe :: a -> Maybe a -> a
fromMaybe :: forall a. a -> Maybe a -> a
fromMaybe a
a = a -> (a -> a) -> Maybe a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
a a -> a
forall a. a -> a
id
{-# INLINABLE fromMaybe #-}
mapMaybe :: (a -> Maybe b) -> [a] -> [b]
mapMaybe :: forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe a -> Maybe b
p = (a -> [b] -> [b]) -> [b] -> [a] -> [b]
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\a
e [b]
xs -> [b] -> (b -> [b]) -> Maybe b -> [b]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [b]
xs (b -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
xs) (a -> Maybe b
p a
e)) []
{-# INLINABLE mapMaybe #-}