Zip

<script src="./point_src/functions/zip"></script>

The zip function combines multiple arrays by pairing elements at the same index position. It returns an iterator that yields tuples of corresponding elements.

The zip() function is a generator for memory-efficient iteration:

// Zip two split lines together
for(let pair of zip(line1.splits, line2.splits)) {
    (new PointList(...pair)).pen.line(ctx)
}

// Zip three arrays
for(let [a, b, c] of zip(arr1, arr2, arr3)) {
    console.log(a, b, c)
}

// Convert to array
const pairs = [...zip(splits1, splits2)]

For eager evaluation, use zipArray() which returns an array immediately:

const pairs = zipArray(splits1, splits2)
pairs.forEach((pair) => {
    (new PointList(...pair)).pen.line(ctx)
})
Meta Data
title Zip
dependencies ()
unused_keys ()
unknown_keys ()
filepath_exists True
path functions/zip
filepath functions/zip.js
clean_files ()