Hyperlinkv0.8.0-beta.28

HashSet

HashSet.mapconsteffect/HashSet.ts:480
<V, U>(f: (value: V) => U): (self: HashSet<V>) => HashSet<U>
<V, U>(self: HashSet<V>, f: (value: V) => U): HashSet<U>

Maps each value in the HashSet using the provided function.

Example (Mapping HashSet values)

import { HashSet } from "effect"

const numbers = HashSet.make(1, 2, 3)
const doubled = HashSet.map(numbers, (n) => n * 2)

console.log(Array.from(doubled).sort()) // [2, 4, 6]
console.log(HashSet.size(doubled)) // 3

// Mapping can reduce size if function produces duplicates
const strings = HashSet.make("apple", "banana", "cherry")
const lengths = HashSet.map(strings, (s) => s.length)
console.log(Array.from(lengths).sort()) // [5, 6] (apple=5, banana=6, cherry=6)
mapping
Source effect/HashSet.ts:4807 lines
export const map: {
  <V, U>(f: (value: V) => U): (self: HashSet<V>) => HashSet<U>
  <V, U>(self: HashSet<V>, f: (value: V) => U): HashSet<U>
} = Dual.dual<
  <V, U>(f: (value: V) => U) => (self: HashSet<V>) => HashSet<U>,
  <V, U>(self: HashSet<V>, f: (value: V) => U) => HashSet<U>
>(2, internal.map)
Referenced by 1 symbols