Left package:rebase

Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.
Laws:
left'dimap swapE swapE . right' where
swapE :: Either a b -> Either b a
swapE = either Right Left
rmap Leftlmap Left . left'
lmap (right f) . left'rmap (right f) . left'
left' . left'dimap assocE unassocE . left' where
assocE :: Either (Either a b) c -> Either a (Either b c)
assocE (Left (Left a)) = Left a
assocE (Left (Right b)) = Right (Left b)
assocE (Right c) = Right (Right c)
unassocE :: Either a (Either b c) -> Either (Either a b) c
unassocE (Left a) = Left (Left a)
unassocE (Right (Left b)) = Left (Right b)
unassocE (Right (Right c)) = Right c
Any instance of ArrowApply can be made into an instance of ArrowChoice by defining left = leftApp.
Maybe get the Left side of an Either.
leftToMaybeeither Just (const Nothing)
Using Control.Lens:
leftToMaybe ≡ preview _Left
leftToMaybe x ≡ x^?_Left
>>> leftToMaybe (Left 12)
Just 12
>>> leftToMaybe (Right 12)
Nothing
Extracts from a list of Either all the Left elements. All the Left elements are extracted in order.

Examples

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

>>> lefts list
["foo","bar","baz"]
A more meaningful and conflict-free alias for first.
Return the contents of a Left-value or a default value otherwise.

Examples

Basic usage:
>>> fromLeft 1 (Left 3)
3

>>> fromLeft 1 (Right "foo")
1
Extracts the element out of a Left and throws an error if its argument take the form Right _. Using Control.Lens:
fromLeft' x ≡ x^?!_Left
>>> fromLeft' (Left 12)
12
Return True if the given value is a Left-value, False otherwise.

Examples

Basic usage:
>>> isLeft (Left "foo")
True

>>> isLeft (Right 3)
False
Assuming a Left value signifies some sort of error, we can use isLeft to write a very simple error-reporting function that does absolutely nothing in the case of success, and outputs "ERROR" if any error occurred. This example shows how isLeft 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 (isLeft e) $ putStrLn "ERROR"

>>> report (Right 1)

>>> report (Left "parse error")
ERROR
Maybe produce a Left, otherwise produce a Right.
>>> maybeToLeft "default" (Just 12)
Left 12
>>> maybeToLeft "default" Nothing
Right "default"
Laws:
unleftunright . dimap swapE swapE where
swapE :: Either a b -> Either b a
swapE = either Right Left
rmap (either id absurd) ≡ unleft . lmap (either id absurd)
unfirst . rmap (second f) ≡ unfirst . lmap (second f)
unleft . unleftunleft . dimap assocE unassocE where
assocE :: Either (Either a b) c -> Either a (Either b c)
assocE (Left (Left a)) = Left a
assocE (Left (Right b)) = Right (Left b)
assocE (Right c) = Right (Right c)
unassocE :: Either a (Either b c) -> Either (Either a b) c
unassocE (Left a) = Left (Left a)
unassocE (Right (Left b)) = Left (Right b)
unassocE (Right (Right c)) = Right c
A synonym of whenRight.
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. Using Control.Lens:
whenLeft ≡ forOf_ _Left
>>> whenLeft (Left 12) print
12