Skip to content

filter

Creates a new Set containing only the values for which the predicate returns true.

Available since v3.0.3

import { filter } from '@helpers4/set';
// or, from the all-in-one package (same code, one install):
import { filter } from 'helpers4/set';
filter<T>(set: ReadonlySet<T>, predicate: function): Set<T>
ParameterTypeDescription
setReadonlySet<T>The Set to filter
predicatefunctionFunction invoked with each value — return true to keep it

Set<T> — A new Set with only the matching values

Creates a new Set with only the values that satisfy the predicate.

filter(new Set([1, 2, 3, 4]), value => value % 2 === 0)
// => Set(2) { 2, 4 }

View source on GitHub