Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Utilites to work with Either
data type.
Synopsis
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- maybeToLeft :: r -> Maybe l -> Either l r
- maybeToRight :: l -> Maybe r -> Either l r
- leftToMaybe :: Either l r -> Maybe l
- rightToMaybe :: Either l r -> Maybe r
- whenLeft :: Applicative f => Either l r -> (l -> f ()) -> f ()
- whenLeftM :: Monad m => m (Either l r) -> (l -> m ()) -> m ()
- whenRight :: Applicative f => Either l r -> (r -> f ()) -> f ()
- whenRightM :: Monad m => m (Either l r) -> (r -> m ()) -> m ()
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 #
maybeToRight :: l -> Maybe r -> Either l r Source #
leftToMaybe :: Either l r -> Maybe l Source #
rightToMaybe :: Either l r -> Maybe r Source #
whenLeft :: Applicative f => Either l r -> (l -> f ()) -> f () Source #
whenRight :: Applicative f => Either l r -> (r -> f ()) -> f () Source #