Safe Haskell | Safe |
---|---|

Language | Haskell98 |

Utilities for the `Either`

type

- 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]
- tests :: IO Bool

# Documentation

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

Loop while we have an exception.

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

Monadic version of `either`

with a different argument ordering.

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

`Either`

is bitraversable.

maybeLeft :: Either a b -> Maybe a Source

Safe projection from `Left`

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

maybeRight :: Either a b -> Maybe b Source

Safe projection from `Right`

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

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

Returns

if all elements are
to the `Just`

with tags stripped`Left`

, and otherwise `Nothing`

.