API reference@evolu/commonSet › filterSet

Call Signature

function filterSet<T, S>(
  set: ReadonlySet<T>,
  refinement: RefinementWithIndex<T, S>,
): ReadonlySet<S>;

Defined in: packages/common/src/Set.ts:212

Filters a set using a predicate or refinement function, returning a new readonly set.

When used with a refinement function (with value is Type syntax), TypeScript will narrow the result type.

Example

filterSet(new Set([1, 2, 3, 4, 5]), (x) => x % 2 === 0); // Set {2, 4}

Call Signature

function filterSet<T>(
  set: ReadonlySet<T>,
  predicate: PredicateWithIndex<T>,
): ReadonlySet<T>;

Defined in: packages/common/src/Set.ts:217

With predicate.