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-sidedEitherand contains a value of typeA.Right<B>is a right-sidedEitherand contains a value of typeB.The companion
Either:namespacenamespace provides utilities for working with theEither<A, B>type.Handling failure
Eitheris also used to represent a value which is either a success or a failure.Leftvariant represents a failed value, while theRightvariant represents a successful value.Some combinators for
Eitherare 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 returnEitherto be composed in a way that propogates failures while applying logic to successes -- a useful feature for railway-oriented programming.Using
Eitherwith promisesAsyncEither<A, B>is an alias forPromise<Either<A, B>>. The companionAsyncEither:namespacenamespace 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: