• Finds the position of element which satisfies pred in the list. If the list is infinite and the element is not found, this will hang forever.

    Type Parameters

    • T

    Parameters

    • pred: ((value) => boolean)

      The match condition of element to find.

        • (value): boolean
        • Parameters

          • value: T

          Returns boolean

    Returns ((list) => Option<number>)

    The found position if exists.

    Examples

    import { findIndex, fromArray } from "./list.ts";
    import * as Option from "./option.ts";
    import { assertEquals } from "../deps.ts";

    const list = fromArray([1, 4, 2, 3, 5]);

    assertEquals(findIndex((x: number) => 4 <= x)(list), Option.some(1));
    assertEquals(findIndex((x: number) => 0 <= x)(list), Option.some(0));
    assertEquals(findIndex((x: number) => 8 <= x)(list), Option.none());

Generated using TypeDoc