{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Maybe.Linear
( Maybe (..),
maybe,
fromMaybe,
maybeToList,
catMaybes,
mapMaybe,
)
where
import qualified Data.Functor.Linear as Linear
import Prelude (Maybe (..))
maybe :: b -> (a %1 -> b) -> Maybe a %1 -> b
maybe :: forall b a. b -> (a %1 -> b) -> Maybe a %1 -> b
maybe b
x a %1 -> b
_ Maybe a
Nothing = b
x
maybe b
_ a %1 -> b
f (Just a
y) = a %1 -> b
f a
y
fromMaybe :: a -> Maybe a %1 -> a
fromMaybe :: forall a. a -> Maybe a %1 -> a
fromMaybe a
a Maybe a
Nothing = a
a
fromMaybe a
_ (Just a
a') = a
a'
maybeToList :: Maybe a %1 -> [a]
maybeToList :: forall a. Maybe a %1 -> [a]
maybeToList Maybe a
Nothing = []
maybeToList (Just a
a) = [a
a]
catMaybes :: [Maybe a] %1 -> [a]
catMaybes :: forall a. [Maybe a] %1 -> [a]
catMaybes [] = []
catMaybes (Maybe a
Nothing : [Maybe a]
xs) = forall a. [Maybe a] %1 -> [a]
catMaybes [Maybe a]
xs
catMaybes (Just a
a : [Maybe a]
xs) = a
a forall a. a -> [a] -> [a]
: forall a. [Maybe a] %1 -> [a]
catMaybes [Maybe a]
xs
mapMaybe :: (a %1 -> Maybe b) -> [a] %1 -> [b]
mapMaybe :: forall a b. (a %1 -> Maybe b) -> [a] %1 -> [b]
mapMaybe a %1 -> Maybe b
f [a]
xs = forall a. [Maybe a] %1 -> [a]
catMaybes (forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Linear.fmap a %1 -> Maybe b
f [a]
xs)