Type: Either

class data.either.Either
type Either(α, β) = Left(α) | Right(β)

implements
  Applicative(β), Functor(β), Chain(β), Monad(β), ToString

Represents the logical disjunction between α and β.

Comparing and testing

#isLeft

Either.prototype.isLeft
Boolean

True if the Either(α, β) contains a Left value.

#isRight

Either.prototype.isRight
Boolean

True if the Either(α, β) contains a Right value.

#isEqual()

Either.prototype.isEqual(anEither)
@Either(α, β) => Either(α, β) → Boolean

Tests if two Either(α, β) structures are equal. Compares the contents using reference equality.

Constructing

.Left()

static Either.Left(value)
α → Either(α, β)

Constructs a new Either(α, β) structure holding a Left value. This usually represents a failure, due to the right-bias of this structure.

.of()

static Either.of(value)
β → Either(α, β)

Creates a new Either(α, β) instance holding the Right value β.

.fromNullable()

static Either.fromNullable(value)
α | null | undefined → Either(null | undefined, α)

Constructs a new Either(α, β) structure from a nullable type.

Takes the Left value if the value is null or undefined. Takes the Right case otherwise.

.fromValidation()

static Either.fromValidation(value)
Validation(α, β) → Either(α, β)

Constructs a new Either(α, β) structure from a Validation(α, β) structure.

Converting

#toString()

Either.prototype.toString()
@Either(α, β) => Unit → String

Returns a textual representation of the Either(α, β) structure.

Extracting

#get()

Either.prototype.get()
Raises:
  • TypeError - If the structure has no Right value.
@Either(α, β) => Unit → β :: throws

Extracts the Right value out of the Either(α, β) structure, if it exists.

#getOrElse()

Either.prototype.getOrElse(default)
@Either(α, β) => β → β

Extracts the Right value out of the Either(α, β) structure. If it doesn’t exist, returns a default value.

#merge()

Either.prototype.merge()
@Either(α, β) => Unit → α | β

Returns whichever side of the disjunction that is present.

Transforming

#ap()

Either.prototype.ap(anApplicative)
@Either(α, β → γ), f:Applicative(_) => f(β) → f(γ)

Applies the function inside the Either(α, β) structure to another Applicative type.

#map()

Either.prototype.map(transformation)
@Either(α, β) => (β → γ) → Either(α, γ)

Transforms the Right value of the Either(α, β) structure using a regular unary function.

#chain()

Either.prototype.chain(transformation)
@Either(α, β), m:Monad(_) => (β → m(γ)) → m(γ)

Transforms the Right value of the Either(α, β) structure using an unary function over monads.

#fold()

Either.prototype.fold(leftTransformation, rightTransformation)
@Either(α, β) => (α → γ), (β → γ) → γ

Applies a function to each case in the data structure.

#cata()

Either.prototype.cata(pattern)
@Either(α, β) => { r | Pattern } → γ
type Pattern {
  Left: α → γ,
  Right: β → γ
}

Applies a function to each case in the data structure.

#swap()

Either.prototype.swap()
@Either(α, β) => Unit → Either(β, α)

Swaps the disjunction values.

#bimap()

Either.prototype.bimap(leftTransformation, rightTransformation)
@Either(α, β) => (α → γ), (β → δ) → Either(γ, δ)

Maps both sides of the disjunction.

#leftMap()

Either.prototype.leftMap(transformation)
@Either(α, β) => (α → γ) → Either(γ, β)

Maps the left side of the disjunction.

#orElse()

Either.prototype.orElse(transformation)
@Either(α, β) => (α → Either(γ, β)) → Either(γ, β)

Transforms the Left value into a new Either(α, β) structure.