import { array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { partition } = array;
Partition a ReadonlyArray into two ReadonlyArrays using a predicate or refinement to do the sorting. If the predicate or refinement returns true for a value, the value is pushed into the first array in a Pair, otherwise it is pushed into the second array in a pair.
Examples
Example 1
Example 1
import * as A from "./array.ts";
import { pipe } from "./fn.ts";
const result = pipe(
A.range(10, 1), // [1, 2, 3, ..., 10]
A.partition(n => n % 2 === 0),
); // Pair<[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]>
Type Parameters
B extends A
Parameters
predicate: (a: A, index: number) => boolean