Either is also used to represent a value which is either a success or a
failure. Left variant represents a failed value, while the Right variant
represents a successful value.
Some combinators for Either are specialized for this failure-handling
use case, and provide a right-biased behavior that "short-circuits" a
computation on the first Left. This behavior allows functions that return
Either to be composed in a way that propogates failures while applying
logic to successes -- a useful feature for railway-oriented programming.
AsyncEither<A, B> is an alias for
Promise<Either<A, B>>. The companion AsyncEither:namespace
namespace provides utilities for working with the AsyncEither<A, B> type.
To accommodate promise-like values, this module also provides the
AsyncEitherLike<A, B> type as an alias for
PromiseLike<Either<A, B>>.
Functional unions and railway-oriented programming.
Remarks
Either<A, B>
is a type that represents one of two values. It is represented by two variants:Left<A>
andRight<B>
.Left<A>
is a left-sidedEither
and contains a value of typeA
.Right<B>
is a right-sidedEither
and contains a value of typeB
.The companion
Either:namespace
namespace provides utilities for working with theEither<A, B>
type.Handling failure
Either
is also used to represent a value which is either a success or a failure.Left
variant represents a failed value, while theRight
variant represents a successful value.Some combinators for
Either
are specialized for this failure-handling use case, and provide a right-biased behavior that "short-circuits" a computation on the firstLeft
. This behavior allows functions that returnEither
to be composed in a way that propogates failures while applying logic to successes -- a useful feature for railway-oriented programming.Using
Either
with promisesAsyncEither<A, B>
is an alias forPromise<Either<A, B>>
. The companionAsyncEither:namespace
namespace provides utilities for working with theAsyncEither<A, B>
type.To accommodate promise-like values, this module also provides the
AsyncEitherLike<A, B>
type as an alias forPromiseLike<Either<A, B>>
.Importing from this module
The types and namespaces from this module can be imported under the same aliases:
Or, they can be imported and aliased separately: