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

Portabilityportable
Stabilityprovisional
Maintainergcross@haskell.org

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 _.

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.