Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.Maybe.Strict

Contents

- Collection operations.
- Conditionals and loops.
- Monads and Maybe.
- Orphan instances

Description

A strict version of the `Maybe` type.

Import qualified, as in `import qualified Agda.Utils.Maybe.Strict as Strict`

Copyright : (c) 2006-2007 Roman Leshchinskiy (c) 2013 Simon Meier License : BSD-style (see the file LICENSE)

Copyright : (c) 2014 Andreas Abel

Synopsis

- module Data.Strict.Maybe
- toStrict :: Maybe a -> Maybe a
- toLazy :: Maybe a -> Maybe a
- listToMaybe :: [a] -> Maybe a
- maybeToList :: Maybe a -> [a]
- catMaybes :: [Maybe a] -> [a]
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- unionMaybeWith :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
- unzipMaybe :: Maybe (a, b) -> (Maybe a, Maybe b)
- filterMaybe :: (a -> Bool) -> a -> Maybe a
- forMaybe :: [a] -> (a -> Maybe b) -> [b]
- caseMaybe :: Maybe a -> b -> (a -> b) -> b
- maybeM :: Monad m => m b -> (a -> m b) -> m (Maybe a) -> m b
- fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a
- caseMaybeM :: Monad m => m (Maybe a) -> m b -> (a -> m b) -> m b
- ifJustM :: Monad m => m (Maybe a) -> (a -> m b) -> m b -> m b
- whenJust :: Monad m => Maybe a -> (a -> m ()) -> m ()
- whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()

# Documentation

module Data.Strict.Maybe

toStrict :: Maybe a -> Maybe a #

toLazy :: Maybe a -> Maybe a #

listToMaybe :: [a] -> Maybe a #

Analogous to `listToMaybe` in Data.Maybe.

maybeToList :: Maybe a -> [a] #

Analogous to `maybeToList` in Data.Maybe.

catMaybes :: [Maybe a] -> [a] #

Analogous to `catMaybes` in Data.Maybe.

mapMaybe :: (a -> Maybe b) -> [a] -> [b] #

Analogous to `mapMaybe` in Data.Maybe.

# Collection operations.

unionMaybeWith :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a #

`unionWith` for collections of size <= 1.

unzipMaybe :: Maybe (a, b) -> (Maybe a, Maybe b) #

Unzipping a list of length <= 1.

filterMaybe :: (a -> Bool) -> a -> Maybe a #

Filtering a singleton list.

    filterMaybe p a = listToMaybe (filter p [a])

# Conditionals and loops.

forMaybe :: [a] -> (a -> Maybe b) -> [b] #

Version of `mapMaybe` with different argument ordering.

caseMaybe :: Maybe a -> b -> (a -> b) -> b #

Version of `maybe` with different argument ordering. Often, we want to case on a `Maybe`, do something interesting in the `Just` case, but only a default action in the `Nothing` case. Then, the argument ordering of `caseMaybe` is preferable.

    caseMaybe m err f = flip (maybe err) m f

# Monads and Maybe.

maybeM :: Monad m => m b -> (a -> m b) -> m (Maybe a) -> m b #

Monadic version of `maybe`.

fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a #

Monadic version of `fromMaybe`.

caseMaybeM :: Monad m => m (Maybe a) -> m b -> (a -> m b) -> m b #

Monadic version of `caseMaybe`. That is, `maybeM` with a different argument ordering.

ifJustM :: Monad m => m (Maybe a) -> (a -> m b) -> m b -> m b #

`caseMaybeM` with flipped branches.

whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () #

A more telling name for `forM` for the `Maybe` collection type. Or: `caseMaybe` without the `Nothing` case.

whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m () #

`caseMaybeM` without the `Nothing` case.

# Orphan instances

Foldable Maybe # |
Methods fold :: Monoid m => Maybe m -> m # foldMap :: Monoid m => (a -> m) -> Maybe a -> m # foldr :: (a -> b -> b) -> b -> Maybe a -> b # foldr' :: (a -> b -> b) -> b -> Maybe a -> b # foldl :: (b -> a -> b) -> b -> Maybe a -> b # foldl' :: (b -> a -> b) -> b -> Maybe a -> b # foldr1 :: (a -> a -> a) -> Maybe a -> a # foldl1 :: (a -> a -> a) -> Maybe a -> a # toList :: Maybe a -> [a] # null :: Maybe a -> Bool # length :: Maybe a -> Int # elem :: Eq a => a -> Maybe a -> Bool # maximum :: Ord a => Maybe a -> a # minimum :: Ord a => Maybe a -> a # sum :: Num a => Maybe a -> a # product :: Num a => Maybe a -> a #
Traversable Maybe # |
Methods traverse :: Applicative f => (a -> f b) -> Maybe a -> f (Maybe b) # sequenceA :: Applicative f => Maybe (f a) -> f (Maybe a) # mapM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b) # sequence :: Monad m => Maybe (m a) -> m (Maybe a) #
Data a => Data (Maybe a) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Maybe a -> c (Maybe a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Maybe a) # toConstr :: Maybe a -> Constr # dataTypeOf :: Maybe a -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Maybe a)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Maybe a)) # gmapT :: (forall b. Data b => b -> b) -> Maybe a -> Maybe a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r # gmapQ :: (forall d. Data d => d -> u) -> Maybe a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Maybe a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) #
Generic (Maybe a) # |
Associated Types type Rep (Maybe a) :: * -> * # Methods from :: Maybe a -> Rep (Maybe a) x # to :: Rep (Maybe a) x -> Maybe a #
Monoid a => Semigroup (Maybe a) # |
Methods (<>) :: Maybe a -> Maybe a -> Maybe a # sconcat :: NonEmpty (Maybe a) -> Maybe a # stimes :: Integral b => b -> Maybe a -> Maybe a #
Monoid a => Monoid (Maybe a) # |
Methods mempty :: Maybe a # mappend :: Maybe a -> Maybe a -> Maybe a # mconcat :: [Maybe a] -> Maybe a #
Binary a => Binary (Maybe a) # |
Methods put :: Maybe a -> Put # get :: Get (Maybe a) # putList :: [Maybe a] -> Put #
NFData a => NFData (Maybe a) # |
Methods rnf :: Maybe a -> () #
Null (Maybe a) # |
Methods empty :: Maybe a # null :: Maybe a -> Bool #