import { curryN } from "@unboxing/function"; import { ArrPred } from '@unboxing/core' interface Filter { (fn: ArrPred, arr: ArrayLike): T[]; (fn: ArrPred): (arr: ArrayLike) => T[]; } /** * Takes a predicate and a "arr", and returns a new array of the * same type containing the members of the given arr which satisfy the * given predicate. */ export const filterArray = curryN(2, (fn: ArrPred, arr: ArrayLike = []) => { const result = []; for (let i = 0; i < arr.length; i++) { if (fn(arr[i], i, arr)) { result.push(arr[i]); } } return result; }) as Filter