import { unzipWith } from "https://deno.land/x/froebel@v0.18.0/unzip.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
)
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'