Hyperlinkv0.8.0-beta.28

MutableHashSet

MutableHashSet.fromIterableconsteffect/MutableHashSet.ts:189
<K = never>(keys: Iterable<K>): MutableHashSet<K>

Creates a MutableHashSet from an iterable collection of values. Duplicates are automatically removed.

When to use

Use to build a mutable hash set from any iterable of values.

Example (Creating a set from an iterable)

import { MutableHashSet } from "effect"

const values = ["apple", "banana", "apple", "cherry", "banana"]
const set = MutableHashSet.fromIterable(values)

console.log(MutableHashSet.size(set)) // 3
console.log(Array.from(set)) // ["apple", "banana", "cherry"]

// Works with any iterable
const fromSet = MutableHashSet.fromIterable(new Set([1, 2, 3]))
console.log(MutableHashSet.size(fromSet)) // 3

// From string characters
const fromString = MutableHashSet.fromIterable("hello")
console.log(Array.from(fromString)) // ["h", "e", "l", "o"]
constructors
export const fromIterable = <K = never>(keys: Iterable<K>): MutableHashSet<K> =>
  fromHashMap(MutableHashMap.fromIterable(Array.from(keys).map((k) => [k, true])))
Referenced by 1 symbols