API reference@evolu/commonSet › mapSet

Call Signature

function mapSet<T, U>(
  set: NonEmptyReadonlySet<T>,
  mapper: (item: T) => U,
): NonEmptyReadonlySet<U>;

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

Maps a set using a mapper function, returning a new readonly set.

Preserves non-empty type.

Note: If the mapper produces duplicate values, the resulting set will have fewer elements.

Example

mapSet(new Set([1, 2, 3]), (x) => x * 2); // Set {2, 4, 6}
mapSet(new Set([1, 2, 3]), (x) => x % 2); // Set {1, 0} (duplicates merged)

Call Signature

function mapSet<T, U>(
  set: ReadonlySet<T>,
  mapper: (item: T) => U,
): ReadonlySet<U>;

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

Possibly empty set.