VDL Plugin SDK

zipWith

Import from @varavel/vdl-plugin-sdk/utils/arrays.

Utility functions re-exported from es-toolkit (MIT License). See https://github.com/toss/es-toolkit for more details.

Call Signature

function zipWith<T, R>(arr1, combine): R[];

Combines multiple arrays into a single array using a custom combiner function.

This function takes multiple arrays and a combiner function, and returns a new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.

Type Parameters

Type ParameterDescription
TThe type of elements in the first array.
RThe type of elements in the resulting array.

Parameters

ParameterTypeDescription
arr1readonly T[]The first array to zip.
combine(item, index) => RThe combiner function that takes corresponding elements from each array, their index, and returns a single value.

Returns

R[]

A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.

Examples

// Example usage with two arrays:
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const result = zipWith(arr1, arr2, (a, b) => a + b);
// result will be [5, 7, 9]
// Example usage with three arrays:
const arr1 = [1, 2];
const arr2 = [3, 4];
const arr3 = [5, 6];
const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`);
// result will be [`135`, `246`]

Call Signature

function zipWith<T, U, R>(
   arr1, 
   arr2, 
   combine
): R[];

Combines two arrays into a single array using a custom combiner function.

Type Parameters

Type ParameterDescription
TThe type of elements in the first array.
UThe type of elements in the second array.
RThe type of elements in the resulting array.

Parameters

ParameterTypeDescription
arr1readonly T[]The first array to zip.
arr2readonly U[]The second array to zip.
combine(item1, item2, index) => RThe combiner function that takes corresponding elements from each array, their index, and returns a single value.

Returns

R[]

A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.

Call Signature

function zipWith<T, U, V, R>(
   arr1, 
   arr2, 
   arr3, 
   combine
): R[];

Combines three arrays into a single array using a custom combiner function.

Type Parameters

Type ParameterDescription
TThe type of elements in the first array.
UThe type of elements in the second array.
VThe type of elements in the third array.
RThe type of elements in the resulting array.

Parameters

ParameterTypeDescription
arr1readonly T[]The first array to zip.
arr2readonly U[]The second array to zip.
arr3readonly V[]The third array to zip.
combine(item1, item2, item3, index) => RThe combiner function that takes corresponding elements from each array, their index, and returns a single value.

Returns

R[]

A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.

Call Signature

function zipWith<T, U, V, W, R>(
   arr1, 
   arr2, 
   arr3, 
   arr4, 
   combine
): R[];

Combines four arrays into a single array using a custom combiner function.

Type Parameters

Type ParameterDescription
TThe type of elements in the first array.
UThe type of elements in the second array.
VThe type of elements in the third array.
WThe type of elements in the fourth array.
RThe type of elements in the resulting array.

Parameters

ParameterTypeDescription
arr1readonly T[]The first array to zip.
arr2readonly U[]The second array to zip.
arr3readonly V[]The third array to zip.
arr4readonly W[]The fourth array to zip.
combine(item1, item2, item3, item4, index) => RThe combiner function that takes corresponding elements from each array, their index, and returns a single value.

Returns

R[]

A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.