• Splits the list into a tuple of the longest prefix satisfies pred and the rest. It is equivalent to [takeWhile(pred)(list), dropWhile(pred)(list)].

    Type Parameters

    • T

    Parameters

    • pred: ((t) => boolean)

      The condition to split.

        • (t): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns ((list) => [List<T>, List<T>])

    The tuple of split of the list.

    Examples

    import { fromArray, span, toArray } from "./list.ts";
    import { assertEquals } from "../deps.ts";

    {
    const [left, right] = span((x: number) => x < 3)(
    fromArray([1, 2, 3, 4, 1, 2, 3, 4]),
    );
    assertEquals(toArray(left), [1, 2]);
    assertEquals(toArray(right), [3, 4, 1, 2, 3, 4]);
    }
    {
    const [left, right] = span((x: number) => x < 9)(fromArray([1, 2, 3]));
    assertEquals(toArray(left), [1, 2, 3]);
    assertEquals(toArray(right), []);
    }
    {
    const [left, right] = span((x: number) => x < 0)(fromArray([1, 2, 3]));
    assertEquals(toArray(left), []);
    assertEquals(toArray(right), [1, 2, 3]);
    }

Generated using TypeDoc