fromRight -package:pipes-fluid

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
Extract the right value or a default.
fromRight b ≡ either (const b) id
>>> fromRight "hello" (Right "world")
"world"
>>> fromRight "hello" (Left 42)
"hello"
Take a Right to a value, crashes on a Left
Extracts the element out of a Right and throws an error if the argument is a Left.
Return the contents of a Right-value or a default value otherwise. @since base-4.10.0.0

Examples

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

>>> fromRight 1 (Left "foo")
1
The fromRight function extracts the element out of a Right and throws an error if its argument take the form Left _.
Extracts value from Right or return given default value.
>>> fromRight 0 (Left 3)
0

>>> fromRight 0 (Right 5)
5
Return the value from the right component. The behavior is undefined if passed a left value, i.e., it can return any value.
>>> fromRight (sRight (literal 'a') :: SEither Integer Char)
'a' :: SChar

>>> prove $ \x -> fromRight (sRight x :: SEither Char Integer) .== (x :: SInteger)
Q.E.D.

>>> sat $ \x -> x .== (fromRight (sLeft (literal 2) :: SEither Integer Char))
Satisfiable. Model:
s0 = 'A' :: Char
Note how we get a satisfying assignment in the last case: The behavior is unspecified, thus the SMT solver picks whatever satisfies the constraints, if there is one.
Analogue of fromMaybe.
Construct a VEither from an a. Exists for symmetry with fromLeft. Indeed, this is just another name for VRight (and for pure).
The fromRight' function extracts the element out of a Right and throws an error if its argument is Left. Much like fromJust, using this function in polished code is usually a bad idea.
\x -> fromRight' (Right x) == x
\x -> fromRight' (Left  x) == undefined
Extracts the element out of a Right and throws an error if its argument take the form Left _. Using Control.Lens:
fromRight' x ≡ x^?!_Right
>>> fromRight' (Right 12)
12
Return the contents of a Right'-value or errors out.
Analogue of fromMaybeM.
This is the same as from rightMonoidalUpdate but doesn't depend on the lens Library.
fromRight but with a better error message if it fails. Use this only where it shouldn't fail!
Pad a builder from the right side to the specified length with the specified character.
>>> padFromRight 5 ' ' "123"
"123  "
>>> padFromRight 5 ' ' "123456"
"123456"