• Returns None if optA is None, otherwise calls optB and return the result. This is an implementation of FlatMap. The order of arguments is reversed because of that it is useful for partial applying.

    Type Parameters

    • T

    • U

    Parameters

    • optB: ((t) => Option<U>)

      The function returns second optional when used optA is Some.

    Returns ((optA) => Option<U>)

    optB or a None.

    Examples

    import { andThen, Option, some, none } from "./option.ts";
    import { assertEquals } from "../deps.ts";

    const sqrtThenToString = (num: number): Option<string> =>
    0 <= num ? some(Math.sqrt(num).toString()) : none();

    const applied = andThen(sqrtThenToString);
    assertEquals(applied(some(4)), some("2"));
    assertEquals(applied(some(-1)), none());
    assertEquals(applied(none()), none());

Generated using TypeDoc