Proposal for Zip
eloytoro opened this issue · comments
Keeping it simple, only takes into account values up to the minimum of both array's length
Nice, thanks for implementing this Eloy!
I was thinking about implementing a ZipWith
function too that would take a callback as parameter, similar to lodash's zipWith, and implement Zip using it. Do you want to give it a shot?
I'll do this one, transforming this proposal to a tail recursive optimized one.
type ZipImpl<arr1 extends unknown[],arr2 extends unknown[], acc extends unknown[]= []> =
[arr1, arr2] extends [[infer item1, ...infer rest1], [infer item2, ...infer rest2]]
? ZipImpl<rest1, rest2,[...acc,[item1, item2]]>
: acc
interface Zip extends Fn {
output: this["input"] extends [infer arr1 extends unknown[], infer arr2 extends unknown[]]
? ZipImpl<arr1,arr2>
: never
}