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

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.Either

Description

Utilities for the `Either` type

Synopsis

- whileLeft :: Monad m => (a -> Either b c) -> (a -> b -> m a) -> (a -> c -> m d) -> a -> m d
- caseEitherM :: Monad m => m (Either a b) -> (a -> m c) -> (b -> m c) -> m c
- mapEither :: (a -> c) -> (b -> d) -> Either a b -> Either c d
- mapLeft :: (a -> c) -> Either a b -> Either c b
- mapRight :: (b -> d) -> Either a b -> Either a d
- traverseEither :: Functor f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d)
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- fromLeft :: (b -> a) -> Either a b -> a
- fromRight :: (a -> b) -> Either a b -> b
- maybeLeft :: Either a b -> Maybe a
- maybeRight :: Either a b -> Maybe b
- allLeft :: [Either a b] -> Maybe [a]
- allRight :: [Either a b] -> Maybe [b]
- maybeToEither :: Maybe a -> Either () a

# Documentation

whileLeft :: Monad m => (a -> Either b c) -> (a -> b -> m a) -> (a -> c -> m d) -> a -> m d #

Loop while we have an exception.

caseEitherM :: Monad m => m (Either a b) -> (a -> m c) -> (b -> m c) -> m c #

Monadic version of `either` with a different argument ordering.

mapEither :: (a -> c) -> (b -> d) -> Either a b -> Either c d #

`Either` is a bifunctor.

mapLeft :: (a -> c) -> Either a b -> Either c b #

'Either _ b' is a functor.

mapRight :: (b -> d) -> Either a b -> Either a d #

'Either a' is a functor.

traverseEither :: Functor f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) #

`Either` is bitraversable.

isLeft :: Either a b -> Bool #

Returns `True` iff the argument is ``Left` x` for some `x`. Note: from `base >= 4.7.0.0` already present in `Data.Either`.

isRight :: Either a b -> Bool #

Returns `True` iff the argument is ``Right` x` for some `x`. Note: from `base >= 4.7.0.0` already present in `Data.Either`.

fromLeft :: (b -> a) -> Either a b -> a #

Analogue of `fromMaybe`.

fromRight :: (a -> b) -> Either a b -> b #

Analogue of `fromMaybe`.

maybeLeft :: Either a b -> Maybe a #

Safe projection from `Left`. `maybeLeft (Left a) = Just a maybeLeft Right{} = Nothing`

maybeRight :: Either a b -> Maybe b #

Safe projection from `Right`. `maybeRight (Right b) = Just b maybeRight Left{} = Nothing`

allLeft :: [Either a b] -> Maybe [a] #

Returns ``Just` with tags stripped` if all elements are to the `Left`, and otherwise `Nothing`.

allRight :: [Either a b] -> Maybe [b] #

Returns ``Just` with tags stripped` if all elements are to the right, and otherwise `Nothing`.

     allRight xs ==
       if all isRight xs then
         Just (map ((Right x) -> x) xs)
        else
         Nothing

maybeToEither :: Maybe a -> Either () a #

Convert `Maybe` to ``Either` ()'`