Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 1.9 KB

Either.md

File metadata and controls

69 lines (52 loc) · 1.9 KB

Module Data.Either

Either

data Either a b
  = Left a
  | Right b

The Either type is used to represent a choice between two types of value.

A common use case for Either is error handling, where Left is used to carry an error value and Right is used to carry a success value.

Instances
instance functorEither :: Functor (Either a)
instance bifunctorEither :: Bifunctor Either
instance applyEither :: Apply (Either e)
instance applicativeEither :: Applicative (Either e)
instance altEither :: Alt (Either e)
instance bindEither :: Bind (Either e)
instance monadEither :: Monad (Either e)
instance extendEither :: Extend (Either e)
instance showEither :: (Show a, Show b) => Show (Either a b)
instance eqEither :: (Eq a, Eq b) => Eq (Either a b)
instance ordEither :: (Ord a, Ord b) => Ord (Either a b)
instance boundedEither :: (Bounded a, Bounded b) => Bounded (Either a b)
instance foldableEither :: Foldable (Either a)
instance bifoldableEither :: Bifoldable Either
instance traversableEither :: Traversable (Either a)
instance bitraversableEither :: Bitraversable Either
instance semiringEither :: (Semiring b) => Semiring (Either a b)
instance semigroupEither :: (Semigroup b) => Semigroup (Either a b)

either

either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c

Takes two functions and an Either value, if the value is a Left the inner value is applied to the first function, if the value is a Right the inner value is applied to the second function.

either f g (Left x) == f x
either f g (Right y) == g y

isLeft

isLeft :: forall a b. Either a b -> Boolean

Returns true when the Either value was constructed with Left.

isRight

isRight :: forall a b. Either a b -> Boolean

Returns true when the Either value was constructed with Right.