either-unwrap-1.1: Functions for probing and unwrapping values inside of Either.

Data.Either.Unwrap

Description

Functions for probing and unwrapping values inside of Either.

Synopsis

# Documentation

isLeft :: Either a b -> BoolSource

The `isLeft` function returns `True` iff its argument is of the form `Left _`.

isRight :: Either a b -> BoolSource

The `isRight` function returns `True` iff its argument is of the form `Right _`.

fromLeft :: Either a b -> aSource

The `fromLeft` function extracts the element out of a `Left` and throws an error if its argument take the form `Right _`.

fromRight :: Either a b -> bSource

The `fromRight` function extracts the element out of a `Right` and throws an error if its argument take the form `Left _`.

mapBoth :: (a -> c) -> (b -> d) -> Either a b -> Either c dSource

The `mapBoth` function takes two functions and applies the first if iff the value takes the form 'Left _' and the second if the value takes the form 'Right _'.

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

The `mapLeft` function takes a function and applies it to an Either value iff the value takes the form 'Left _'.

mapRight :: (b -> c) -> Either a b -> Either a cSource

The `mapLeft` function takes a function and applies it to an Either value iff the value takes the form 'Left _'.

eitherM :: Monad m => Either a b -> (a -> m c) -> (b -> m c) -> m cSource

The `eitherM` function takes an `Either` value and two functions which return monads. If the argument takes the form `Left _` then the element within is passed to the first function, otherwise the element within is passed to the second function.

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

The `whenLeft` function takes an `Either` value and a function which returns a monad. The monad is only executed when the given argument takes the form `Left _`, otherwise it does nothing.

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

The `whenLeft` function takes an `Either` value and a function which returns a monad. The monad is only executed when the given argument takes the form `Right _`, otherwise it does nothing.

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

A synonym of `whenRight`.

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

A synonym of `whenLeft`.