Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/optio/operators/logical.ts>andThen

Minimum option type port of Rust
Latest
function andThen
import { andThen } from "https://deno.land/x/optio@1.0.0/operators/logical.ts";

Returns None if the option is None, otherwise calls fn with the wrapped value and returns the result.

Examples

Example 1

import { None, Some } from "https://deno.land/x/optio/spec.ts";
import { andThen } from "https://deno.land/x/optio/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

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

assertEquals(andThen(Some(3), square), Some(9));
assertEquals(andThen(None, square), None);

Parameters

option: Option<T>
fn: (value: T) => U