<Keys extends ReadonlyArray<unknown>>(...keys: Keys): MutableHashSet<
Keys[number]
>Creates a MutableHashSet from a variable number of values. Duplicates are automatically removed.
When to use
Use to build a mutable hash set from explicit values.
Example (Creating a set from values)
import { MutableHashSet } from "effect"
const set = MutableHashSet.make("apple", "banana", "apple", "cherry")
console.log(MutableHashSet.size(set)) // 3
console.log(Array.from(set)) // ["apple", "banana", "cherry"]
// With numbers
const numbers = MutableHashSet.make(1, 2, 3, 2, 1)
console.log(MutableHashSet.size(numbers)) // 3
console.log(Array.from(numbers)) // [1, 2, 3]
// Mixed types
const mixed = MutableHashSet.make("hello", 42, true, "hello")
console.log(MutableHashSet.size(mixed)) // 3export const const make: <
Keys extends ReadonlyArray<unknown>
>(
...keys: Keys
) => MutableHashSet<Keys[number]>
Creates a MutableHashSet from a variable number of values.
Duplicates are automatically removed.
When to use
Use to build a mutable hash set from explicit values.
Example (Creating a set from values)
import { MutableHashSet } from "effect"
const set = MutableHashSet.make("apple", "banana", "apple", "cherry")
console.log(MutableHashSet.size(set)) // 3
console.log(Array.from(set)) // ["apple", "banana", "cherry"]
// With numbers
const numbers = MutableHashSet.make(1, 2, 3, 2, 1)
console.log(MutableHashSet.size(numbers)) // 3
console.log(Array.from(numbers)) // [1, 2, 3]
// Mixed types
const mixed = MutableHashSet.make("hello", 42, true, "hello")
console.log(MutableHashSet.size(mixed)) // 3
make = <function (type parameter) Keys in <Keys extends ReadonlyArray<unknown>>(...keys: Keys): MutableHashSet<Keys[number]>Keys extends interface ReadonlyArray<T>ReadonlyArray<unknown>>(
...keys: Keys extends ReadonlyArray<unknown>keys: function (type parameter) Keys in <Keys extends ReadonlyArray<unknown>>(...keys: Keys): MutableHashSet<Keys[number]>Keys
): 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) Keys in <Keys extends ReadonlyArray<unknown>>(...keys: Keys): MutableHashSet<Keys[number]>Keys[number]> => const fromIterable: <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"]
fromIterable(keys: Keys extends ReadonlyArray<unknown>keys)