Skip to content

map

Creates a new Set with each value transformed by a function. If two values transform to the same result, duplicates collapse — the returned Set may be smaller than the input.

Available since v3.0.3

import { map } from '@helpers4/set';
// or, from the all-in-one package (same code, one install):
import { map } from 'helpers4/set';
map<T, R>(set: ReadonlySet<T>, fn: function): Set<R>
ParameterTypeDescription
setReadonlySet<T>The Set to transform
fnfunctionFunction invoked with each value, returning the new value

Set<R> — A new Set of transformed values

Creates a new Set with each value transformed by a function.

map(new Set([1, 2, 3]), value => value * 10)
// => Set(3) { 10, 20, 30 }

If two values transform to the same result, the Set naturally deduplicates.

map(new Set([1, 2, 3]), () => 'same')
// => Set(1) { 'same' }

View source on GitHub