import { curryN } from "@unboxing/function"; import { CurriedFunction2 } from '@unboxing/core' type MapFunc = (a: U, b: V) => R; interface ZipWith { (fn: MapFunc, list1: ArrayLike, list2: ArrayLike): R[]; (fn: MapFunc, list1: ArrayLike): (list2: ArrayLike) => R[]; (fn: MapFunc): CurriedFunction2, ArrayLike, R[]>; } /** * Creates a new list out of the two supplied by applying the function to each * equally-positioned pair in the lists. The returned list is truncated to the * length of the shorter of the two input lists. */ export const zipWith = curryN(3, (fn: MapFunc, a: ArrayLike = [], b: ArrayLike = []) => { const len = Math.min(a.length, b.length); const result: R[] = new Array(len); for (let i = 0; i < len; i++) { result[i] = fn(a[i], b[i]); } return result; }) as ZipWith