protolude-0.3.4: A small prelude.

Safe Haskell | Safe
Language | Haskell2010

Protolude.Either

Synopsis

- 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
- maybeEmpty :: Monoid b => (a -> b) -> Maybe a -> b
- maybeToEither :: e -> Maybe a -> Either e a
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b

# Documentation

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 #

maybeEmpty :: Monoid b => (a -> b) -> Maybe a -> b #

maybeToEither :: e -> Maybe a -> Either e a #

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

Return the contents of a `Left`-value or a default value otherwise.

#### Examples

Expand

Basic usage:

    >>> fromLeft 1 (Left 3)
    3
    >>> fromLeft 1 (Right "foo")
    1

Since: base-4.10.0.0

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

Return the contents of a `Right`-value or a default value otherwise.

#### Examples

Expand

Basic usage:

    >>> fromRight 1 (Right 3)
    3
    >>> fromRight 1 (Left "foo")
    1

Since: base-4.10.0.0