Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Either

Lean: Hale.Base.Either | Haskell: Data.Either

Overview

Sum type with Left and Right constructors. Right-biased for Functor/Monad instances. Includes partitioning of lists of Either values.

API Mapping

LeanHaskellKind
EitherEitherType
left / rightLeft / RightConstructors
isLeft / isRightisLeft / isRightPredicate
fromLeft / fromRightfromLeft / fromRightAccessor
eithereitherEliminator
mapLeft / mapRightfirst / secondFunction
swapN/AFunction
partitionEitherspartitionEithersFunction

Instances

  • Functor (Either a)
  • Pure (Either a)
  • Bind (Either a)
  • Seq (Either a)
  • Applicative (Either a)
  • Monad (Either a)
  • Bifunctor Either
  • ToString (Either a b) (requires ToString a, ToString b)

Proofs & Guarantees

  • swap_swapswap (swap e) = e (involution)
  • isLeft_not_isRightisLeft e = !isRight e
  • partitionEithers_length — total elements preserved after partitioning

Example

-- Partition a list of Either values
Either.partitionEithers [.left "a", .right 1, .left "b", .right 2]
-- => (["a", "b"], [1, 2])