Function findSlice

  • Returns the first slice of the array (starting with slice(0, 0), then slice(0, 1), etc.) which passes condition. Returns undefined if no slice of the array beginning with the first element passes.

    Example

    import * as A from "flurp/array";
    import * as N from "flurp/number";

    const twoPositive = (arr: ReadonlyArray<number>) => A.count(N.isPositive)(arr) >= 2;
    const firstSlice = A.findSlice(twoPositive);
    firstSlice([2, -4, 1, -5, 6]); // [2, -4, 1]
    firstSlice([2, -4]); // undefined

    Type Parameters

    • T

    Parameters

    • condition: ((a: readonly T[]) => boolean)
        • (a: readonly T[]): boolean
        • Parameters

          • a: readonly T[]

          Returns boolean

    Returns ((arr: readonly T[]) => undefined | T[])

      • (arr: readonly T[]): undefined | T[]
      • Parameters

        • arr: readonly T[]

        Returns undefined | T[]