method AsyncResult.prototype.andThen
AsyncResult.prototype.andThen<U, F extends BaseError>(fn: (value: T) => Result<U, F> | AsyncResult<U, F> | Promise<Result<U, F>>): AsyncResult<U, E | F>

Chains operations that return Results.

Examples

Example 1

const result = fetchUser("123")
  .andThen(user => fetchPermissions(user.id));

Type Parameters

F extends BaseError

Parameters

fn: (value: T) => Result<U, F> | AsyncResult<U, F> | Promise<Result<U, F>>

Function that takes the Ok value and returns a Result, AsyncResult, or Promise

Return Type

A new AsyncResult from the chained operation

Usage

import { AsyncResult } from "result/mod.ts";