VDL Plugin SDK

map

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

function map<T, U>(set, getNewValue): Set<U>;

Creates a new Set with elements transformed by the provided function.

This function takes a Set and a function that generates a new value from each element. It returns a new Set where the elements are the result of applying the function to each element.

Type Parameters

Type ParameterDescription
TThe type of elements in the input Set.
UThe type of elements in the output Set.

Parameters

ParameterTypeDescription
setSet<T>The Set to transform.
getNewValue(value, value2, set) => UA function that generates a new value from an element.

Returns

Set<U>

A new Set with transformed elements.

Example

const set = new Set([1, 2, 3]);
const result = map(set, (value) => value * 2);
// result will be:
// Set(3) { 2, 4, 6 }