import { curryN } from "@unboxing/function"; import { ArrPred } from '@unboxing/core' interface Partition { (fn: ArrPred, list: ArrayLike): [T[], T[]]; (fn: ArrPred): (list: ArrayLike) => [T[], T[]]; } /** * Takes a predicate and a array and returns the * pair of arrays of the same type of elements which do and do not * satisfy, the predicate, respectively. */ export const partition = curryN(2, (fn: ArrPred, arr: ArrayLike = []) => { const t = []; const f = []; for (let i = 0; i < arr.length; i++) { if (fn(arr[i], i, arr)) { t.push(arr[i]); } else { f.push(arr[i]); } } return [t, f]; }) as Partition