ref: 4a43da4f0216e079d71557a256a771f10b4dfd69
dir: /lib/Data/Maybe.hs/
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
module Data.Maybe(module Data.Maybe) where
data Maybe a = Nothing | Just a
maybe :: forall a r . r -> (a -> r) -> Maybe a -> r
maybe r f arg =
case arg of
Nothing -> r
Just a -> f a
fromMaybe :: forall a . a -> Maybe a -> a
fromMaybe a arg =
case arg of
Nothing -> a
Just x -> x
fmapMaybe :: forall a b . (a -> b) -> Maybe a -> Maybe b
fmapMaybe f am =
case am of
Nothing -> Nothing
Just a -> Just (f a)
catMaybes :: forall a . [Maybe a] -> [a]
catMaybes mxs = [ x | Just x <- mxs ]