VDL Plugin SDK

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 ParameterDescription
TThe type of elements in the Set.

Parameters

ParameterTypeDescription
setSet<T>The Set to filter.
callback(value, value2, set) => booleanA 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 }