The condition to split.
The tuple of split of the list.
{
const [left, right] = span((x: number) => x < 3)(
fromArray([1, 2, 3, 4, 1, 2, 3, 4]),
);
expect(toArray(left)).toStrictEqual([1, 2]);
expect(toArray(right)).toStrictEqual([3, 4, 1, 2, 3, 4]);
}
{
const [left, right] = span((x: number) => x < 9)(fromArray([1, 2, 3]));
expect(toArray(left)).toStrictEqual([1, 2, 3]);
expect(toArray(right)).toStrictEqual([]);
}
{
const [left, right] = span((x: number) => x < 0)(fromArray([1, 2, 3]));
expect(toArray(left)).toStrictEqual([]);
expect(toArray(right)).toStrictEqual([1, 2, 3]);
}
Splits the list into a tuple of the longest prefix satisfies
predand the rest. It is equivalent to[takeWhile(pred)(list), dropWhile(pred)(list)].