The condition to split.
The tuple of split of the list.
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
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)]
.