<K = never>(): MutableHashSet<K>Creates an empty MutableHashSet.
When to use
Use to create a fresh mutable set before adding values over time.
Details
Each call returns a new empty set backed by an empty MutableHashMap.
Example (Creating an empty set)
import { MutableHashSet } from "effect"
const set = MutableHashSet.empty<string>()
// Add some values
MutableHashSet.add(set, "apple")
MutableHashSet.add(set, "banana")
MutableHashSet.add(set, "apple") // Duplicate, no effect
console.log(MutableHashSet.size(set)) // 2
console.log(Array.from(set)) // ["apple", "banana"]export const const empty: <
K = never
>() => MutableHashSet<K>
Creates an empty MutableHashSet.
When to use
Use to create a fresh mutable set before adding values over time.
Details
Each call returns a new empty set backed by an empty MutableHashMap.
Example (Creating an empty set)
import { MutableHashSet } from "effect"
const set = MutableHashSet.empty<string>()
// Add some values
MutableHashSet.add(set, "apple")
MutableHashSet.add(set, "banana")
MutableHashSet.add(set, "apple") // Duplicate, no effect
console.log(MutableHashSet.size(set)) // 2
console.log(Array.from(set)) // ["apple", "banana"]
empty = <function (type parameter) K in <K = never>(): MutableHashSet<K>K = never>(): interface MutableHashSet<out V>A mutable hash set for storing unique values with Effect structural equality
support.
When to use
Use to store and mutate a collection of unique values with Effect hashing and
equality semantics.
Details
Operations mutate the set in place. Values that implement Equal / Hash
can be de-duplicated structurally; other values use normal JavaScript
reference or primitive equality.
Example (Using a mutable hash set)
import { MutableHashSet } from "effect"
// Create a mutable hash set
const set: MutableHashSet.MutableHashSet<string> = MutableHashSet.make(
"apple",
"banana"
)
// Add elements
MutableHashSet.add(set, "cherry")
// Check if elements exist
console.log(MutableHashSet.has(set, "apple")) // true
console.log(MutableHashSet.has(set, "grape")) // false
// Iterate over elements
for (const value of set) {
console.log(value) // "apple", "banana", "cherry"
}
// Get size
console.log(MutableHashSet.size(set)) // 3
MutableHashSet<function (type parameter) K in <K = never>(): MutableHashSet<K>K> => const fromHashMap: <V>(
keyMap: MutableHashMap.MutableHashMap<
V,
boolean
>
) => MutableHashSet<V>
fromHashMap(import MutableHashMapMutableHashMap.empty())