Skip to main content
Module

x/froebel/mod.ts>unzipWith

A strictly typed utility library.
Go to Latest
variable unzipWith
import { unzipWith } from "https://deno.land/x/froebel@v0.21.3/mod.ts";

Same as unzip but accepts an unzipper function for each tuple index. The unzipper's return value is used as the value in the list at that index returned from unzipWith.

The unzipper takes the current element as its first argument, an accumulator as second argument (initially undefined) and its return value is the accumulator passed into the next invocation.

Examples

const [nums, str] = unzip( [ [1,'a'], [2,'b'], [3,'c'] ], (n, acc: number[] = []) => [...acc, n], (c, str = '') => str + c )

console.log(nums) // prints: [1, 2, 3] console.log(str) // prints: 'abc'

type

<T extends unknown[], U extends [I in keyof T]: λ<[T[I], any]>>(zipped: [...T][], ...unzippers: U) => [I in keyof U]: ReturnType<U[I]>