Skip to content

aivi.core.either ​

Either L R is a disjoint union with Left L and Right R branches. Use it when both branches are meaningful alternatives. For ordinary success and failure, prefer Result E A.

Type class operations ​

Either E implements Functor, Apply, Applicative, Chain, Monad, Foldable, and Traversable. Ambient map is equivalent to mapRight; pure constructs Right; chain and join short-circuit on Left. apply checks the function's Either first, preserving its Left when both inputs fail. reduce returns the seed for Left and visits the payload once for Right.

traverse transform either sequences the Right payload through any Applicative G, producing G (Either E B). A Left is lifted unchanged with pure; its payload is never passed to the transform. Traversing into Task builds a deferred plan.

Bifunctor Either supplies bimap, equivalent to mapBoth. Import this module's type or helpers to make its instances available.

API ​

ExportTypeBehavior
EitherEither L RThe two-branch type
LeftL -> Either L RConstruct the left branch
RightR -> Either L RConstruct the right branch
isLeftEither L R -> BoolTest for Left
isRightEither L R -> BoolTest for Right
fromLeftEither L R -> Option LExtract a left value when present
fromRightEither L R -> Option RExtract a right value when present
mapLeft(L1 -> L2) -> Either L1 R -> Either L2 RTransform the left branch
mapRight(R1 -> R2) -> Either L R1 -> Either L R2Transform the right branch
mapBoth(L1 -> L2) -> (R1 -> R2) -> Either L1 R1 -> Either L2 R2Transform either branch
fold(L -> C) -> (R -> C) -> Either L R -> CEliminate an Either into one result type
swapEither L R -> Either R LExchange the branches
toOptionEither L R -> Option RKeep Right; discard Left
toResultEither L R -> Result L RMap Left to Err and Right to Ok
fromResultResult E A -> Either E AMap Err to Left and Ok to Right
partitionEithersList (Either L R) -> (List L, List R)Split values into left and right lists while preserving order
aivi
use aivi.core.either (
    Either
    Left
    Right
    fold
)

type Either Text Int -> Text
func describe = value =>
    fold (message => "error: {message}") (number => "value: {number}") value

value example : Text = describe (Right 3)

(c) 2026 by Andreas Herd