Right package:universum

Maps right part of Either to Maybe.
>>> rightToMaybe (Left True)
Nothing

>>> rightToMaybe (Right "aba")
Just "aba"
Extracts from a list of Either all the Right elements. All the Right elements are extracted in order.

Examples

Basic usage:
>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]

>>> rights list
[3,7]
Extracts value from Right or return given default value.
>>> fromRight 0 (Left 3)
0

>>> fromRight 0 (Right 5)
5
Maps Maybe to Either wrapping default value into Left.
>>> maybeToRight True (Just "aba")
Right "aba"

>>> maybeToRight True Nothing
Left True
Applies given action to Either content if Right is given.
Monadic version of whenRight.
Return True if the given value is a Right-value, False otherwise.

Examples

Basic usage:
>>> isRight (Left "foo")
False

>>> isRight (Right 3)
True
Assuming a Left value signifies some sort of error, we can use isRight to write a very simple reporting function that only outputs "SUCCESS" when a computation has succeeded. This example shows how isRight might be used to avoid pattern matching when one does not care about the value contained in the constructor:
>>> import Control.Monad ( when )

>>> let report e = when (isRight e) $ putStrLn "SUCCESS"

>>> report (Left "parse error")

>>> report (Right 1)
SUCCESS