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 Parameter | Description |
|---|---|
T | The type of elements in the input Set. |
U | The type of elements in the output Set. |
Parameters
| Parameter | Type | Description |
|---|---|---|
set | Set<T> | The Set to transform. |
getNewValue | (value, value2, set) => U | A 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 }