Right package:base-compat

Return the contents of a Right-value or a default value otherwise.

Examples

Basic usage:
>>> fromRight 1 (Right 3)
3

>>> fromRight 1 (Left "foo")
1
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