filter
Import from @varavel/vdl-plugin-sdk/utils/sets.
function filter<T>(set, callback): Set<T>;
Filters a Set based on a predicate function.
This function takes a Set and a predicate function, and returns a new Set containing only the elements for which the predicate function returns true.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of elements in the Set. |
Parameters
| Parameter | Type | Description |
|---|---|---|
set | Set<T> | The Set to filter. |
callback | (value, value2, set) => boolean | A predicate function that tests each element. |
Returns
Set<T>
A new Set containing only the elements that satisfy the predicate.
Example
const set = new Set([1, 2, 3, 4, 5]);
const result = filter(set, (value) => value > 2);
// result will be:
// Set(3) { 3, 4, 5 }