Return the contents of a Left-value or a default value otherwise.
Examples
Basic usage:
fromLeft 1 (Left 3)3fromLeft 1 (Right "foo")1
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Modulerelude-1.2.0.0Haskell2010
SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable
Utilities to work with Relude.Either data type.
Return the contents of a Left-value or a default value otherwise.
Basic usage:
fromLeft 1 (Left 3)3fromLeft 1 (Right "foo")1
Return the contents of a Right-value or a default value otherwise.
Basic usage:
fromRight 1 (Right 3)3fromRight 1 (Left "foo")1
Monadic version of whenLeft.
whenLeftM "bar" (pure $ Left 42) (\a -> "success!" <$ print a)42"success!"
whenLeftM "bar" (pure $ Right 42) (\a -> "success!" <$ print a)"bar"
Monadic version of whenLeft_.
whenLeftM_ (pure $ Right 42) putTextLnwhenLeftM_ (pure $ Left "foo") putTextLnfoo
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 "bar" (Left "foo") (\a -> "success!" <$ print a)"bar"
whenRight "bar" (Right 42) (\a -> "success!" <$ print a)42"success!"
Monadic version of whenRight.
whenRightM "bar" (pure $ Left "foo") (\a -> "success!" <$ print a)"bar"
whenRightM "bar" (pure $ Right 42) (\a -> "success!" <$ print a)42"success!"
Monadic version of whenRight_.
whenRightM_ (pure $ Left "foo") printwhenRightM_ (pure $ Right 42) print42