universum-1.7.3: Custom prelude used in Serokell
Safe HaskellSafe
LanguageHaskell2010

Universum.Monad.Either

Description

Utilites to work with Either data type.

Synopsis

Documentation

fromLeft :: a -> Either a b -> a Source #

Extracts value from Left or return given default value.

>>> fromLeft 0 (Left 3)
3
>>> fromLeft 0 (Right 5)
0

fromRight :: b -> Either a b -> b Source #

Extracts value from Right or return given default value.

>>> fromRight 0 (Left 3)
0
>>> fromRight 0 (Right 5)
5

maybeToLeft :: r -> Maybe l -> Either l r Source #

Maps Maybe to Either wrapping default value into Right.

>>> maybeToLeft True (Just "aba")
Left "aba"
>>> maybeToLeft True Nothing
Right True

maybeToRight :: l -> Maybe r -> Either l r Source #

Maps Maybe to Either wrapping default value into Left.

>>> maybeToRight True (Just "aba")
Right "aba"
>>> maybeToRight True Nothing
Left True

leftToMaybe :: Either l r -> Maybe l Source #

Maps left part of Either to Maybe.

>>> leftToMaybe (Left True)
Just True
>>> leftToMaybe (Right "aba")
Nothing

rightToMaybe :: Either l r -> Maybe r Source #

Maps right part of Either to Maybe.

>>> rightToMaybe (Left True)
Nothing
>>> rightToMaybe (Right "aba")
Just "aba"

whenLeft :: Applicative f => Either l r -> (l -> f ()) -> f () Source #

Applies given action to Either content if Left is given.

whenLeftM :: Monad m => m (Either l r) -> (l -> m ()) -> m () Source #

Monadic version of whenLeft.

whenRight :: Applicative f => Either l r -> (r -> f ()) -> f () Source #

Applies given action to Either content if Right is given.

whenRightM :: Monad m => m (Either l r) -> (r -> m ()) -> m () Source #

Monadic version of whenRight.