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

Safe HaskellSafe-Inferred

Agda.Utils.Maybe

Contents

Description

Extend Maybe by common operations for the Maybe type.

Note: since this module is usually imported unqualified, we do not use short names, but all names contain Maybe, Just, or 'Nothing.

Synopsis

Collection operations.

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

unionWith for collections of size <= 1.

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

Unzipping a list of length <= 1.

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

Filtering a singleton list.

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

Conditionals and loops.

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

Version of mapMaybe with different argument ordering.

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

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 bSource

Monadic version of maybe.

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

Monadic version of fromMaybe.

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

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

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

caseMaybeM with flipped branches.

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

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 ()Source

caseMaybeM without the Nothing case.

module Data.Maybe