Right package:rio

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]
_Right targets the value contained in an Either, provided it's a Right. See documentation for _Left.
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
O(n) Right-justify a string to the given length, using the specified fill character on the left. Performs replacement on invalid scalar values. Examples:
>>> justifyRight 7 'x' "bar"
"xxxxbar"
>>> justifyRight 3 'x' "foobar"
"foobar"
O(n) Right-justify a string to the given length, using the specified fill character on the left. Performs replacement on invalid scalar values. Examples:
justifyRight 7 'x' "bar"    == "xxxxbar"
justifyRight 3 'x' "foobar" == "foobar"