Skip to main content
Module

x/result_js/mod.ts>andThen

Minimum result type port of Rust
Latest
function andThen
import { andThen } from "https://deno.land/x/result_js@2.0.0/mod.ts";

Calls fn if the result is Ok, otherwise returns the Err.

Examples

Example 1

import { andThen } from "https://deno.land/x/result_js/operators/logical.ts";
import { Err, Ok } from "https://deno.land/x/result_js/spec.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const square: (value: number) => Ok<number>;

assertEquals(andThen(Ok(3), square), Ok(9));
assertEquals(andThen(Err(1), square), Err(1));

Parameters

result: Result<T, E>
fn: (value: T) => Result<U, E>