Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/async_either.ts

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
import * as fun from "https://deno.land/x/fun@v.2.0.0-alpha.11/async_either.ts";

The AsyncEither datastructure represents an asynchronous operation that can fail. At its heart it is implemented as () => Promise<Either<B, A>>. This thunk makes it a performant but lazy operation at the expense of stack safety.

Functions

Provide an alternative for a failed computation. Useful for implementing defaults.

Apply an argument to a function under the Right side.

Sequentially apply arguments

A dual map function that maps over both Left and Right side of a AsyncEither.

Chain AsyncEither based computations together in a pipeline

Chain AsyncEither based failures, Left sides, useful for recovering from error conditions.

Lift an always succeeding async computation (Async) into a AsyncEither.

Lifts an Either<B,A> into a AsyncEither<B, A>.

Flatten a AsyncEither wrapped in a AsyncEither

Constructs a AsyncEither from a value and wraps it in an inner Left traditionally signaling a failure.

Map a function over the Right side of a AsyncEither

Map a function over the Left side of a AsyncEither

Fold away the inner Either from the AsyncEither leaving us with the result of our computation in the form of a Async

Construct an AsyncEither<B, A> from a value A.

Constructs a AsyncEither from a value and wraps it in an inner Right traditionally signaling a successful computation.

Construct an AsyncEither<B, A> from a value B.

Wraps a Async of A in a try-catch block which upon failure returns B instead. Upon success returns a Right and Left for a failure.

Interfaces

Specifies AsyncEither as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any substitutions and covariant parameter B corresponding to the 1st index of any substitutions.

Type Aliases

The AsyncEither type can best be thought of as an asynchronous function that returns an Either. ie. async () => Promise<Either<B, A>>. This forms the basis of most Promise based asynchronous communication in TypeScript.