relude-0.5.0: Custom prelude from Kowainik

Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

Relude.Monad.Either

Contents

Description

Utilites to work with Either data type.

Synopsis

Documentation

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

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

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

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 #

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 #

Maps left part of Either to Maybe.

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

rightToMaybe :: Either l r -> Maybe r #

Maps right part of Either to Maybe.

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

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

Applies given action to Either content if Left is given and returns the result. In case of Right the default value will be returned.

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

Applies given action to Either content if Left is given.

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

Monadic version of whenLeft.

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

Monadic version of whenLeft_.

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

Applies given action to Either content if Right is given and returns the result. In case of Left the default value will be returned.

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

Applies given action to Either content if Right is given.

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

Monadic version of whenRight.

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

Monadic version of whenRight_.

Orphan instances

IsString str => MonadFail (Either str) # 
Instance details

Methods

fail :: String -> Either str a #