import { min } from "d3-array" ; import { identity } from "./identity" ; interface Zip { ( ... args ) : any [ ] ; combine ( ) : any ; combine ( x ) : Zip ; } export default function zipper ( ) { let combine = identity ; function zip ( ) { const n = arguments . length ; if ( n === 0 ) { return [ ] ; } const m = min ( arguments , d3_zipLength ) ?? 0 ; const zips = new Array ( m ) ; for ( let i = - 1 ; ++ i < m ; ) { for ( let j = - 1 , zip = ( zips [ i ] = new Array ( n ) ) ; ++ j < n ; ) { zip [ j ] = arguments [ j ] [ i ] ; } zips [ i ] = combine . apply ( this , zips [ i ] ) ; } return zips ; } function d3_zipLength ( d ) { return d . length ; } zip . combine = function ( x ) { if ( ! arguments . length ) { return combine ; } combine = x ; return zip ; } ; return zip as Zip ; }