• Returns Some only if opt is a Some and its value satisfies predicate, otherwise returns None.

    Type Parameters

    • T

    Parameters

    • predicate: ((t) => boolean)

      The predicate to filter a value of opt.

        • (t): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns ((opt) => Option<T>)

    The filtered optional.

    Examples

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

    const isEven = filter((x: number) => x % 2 == 0);

    assertEquals(isEven(none()), none());
    assertEquals(isEven(some(3)), none());
    assertEquals(isEven(some(4)), some(4));

Generated using TypeDoc