The condition to split.
The tuple of split of the list.
import { fromArray, spanNot, toArray } from "./list.ts";
import { assertEquals } from "../deps.ts";
{
const [left, right] = spanNot((x: number) => x > 3)(
fromArray([1, 2, 3, 4, 1, 2, 3, 4]),
);
assertEquals(toArray(left), [1, 2, 3]);
assertEquals(toArray(right), [4, 1, 2, 3, 4]);
}
{
const [left, right] = spanNot((x: number) => x < 9)(
fromArray([1, 2, 3]),
);
assertEquals(toArray(left), []);
assertEquals(toArray(right), [1, 2, 3]);
}
{
const [left, right] = spanNot((x: number) => x > 9)(
fromArray([1, 2, 3]),
);
assertEquals(toArray(left), [1, 2, 3]);
assertEquals(toArray(right), []);
}
Generated using TypeDoc
Splits the list into a tuple of the longest prefix does NOT satisfy
pred
and the rest. It is equivalent tospan((item) => !pred(item))
.