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 => a -> Either l r -> (l -> f a) -> f a
- whenLeft_ :: Applicative f => Either l r -> (l -> f ()) -> f ()
- whenLeftM :: Monad m => a -> m (Either l r) -> (l -> m a) -> m a
- whenLeftM_ :: Monad m => m (Either l r) -> (l -> m ()) -> m ()
- whenRight :: Applicative f => a -> Either l r -> (r -> f a) -> f a
- whenRight_ :: Applicative f => Either l r -> (r -> f ()) -> f ()
- whenRightM :: Monad m => a -> m (Either l r) -> (r -> m a) -> m a
- 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 => a -> Either l r -> (l -> f a) -> f a Source #
whenLeft_ :: Applicative f => Either l r -> (l -> f ()) -> f () Source #
whenLeftM :: Monad m => a -> m (Either l r) -> (l -> m a) -> m a Source #
Monadic version of whenLeft
.
whenLeftM_ :: Monad m => m (Either l r) -> (l -> m ()) -> m () Source #
Monadic version of whenLeft_
.
whenRight :: Applicative f => a -> Either l r -> (r -> f a) -> f a Source #
whenRight_ :: Applicative f => Either l r -> (r -> f ()) -> f () Source #
whenRightM :: Monad m => a -> m (Either l r) -> (r -> m a) -> m a Source #
Monadic version of whenRight
.
whenRightM_ :: Monad m => m (Either l r) -> (r -> m ()) -> m () Source #
Monadic version of whenRight_
.