<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"]export const 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 = <function (type parameter) K in <K = never>(keys: Iterable<K>): MutableHashSet<K>K = never>(keys: Iterable<K>keys: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) K in <K = never>(keys: Iterable<K>): MutableHashSet<K>K>): 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>(keys: Iterable<K>): MutableHashSet<K>K> =>
const fromHashMap: <V>(
keyMap: MutableHashMap.MutableHashMap<
V,
boolean
>
) => MutableHashSet<V>
fromHashMap(import MutableHashMapMutableHashMap.fromIterable(var Array: ArrayConstructorArray.ArrayConstructor.from<K>(iterable: Iterable<K> | ArrayLike<K>): K[] (+3 overloads)Creates an array from an iterable object.
from(keys: Iterable<K>keys).Array<K>.map<(boolean | K)[]>(callbackfn: (value: K, index: number, array: K[]) => (boolean | K)[], thisArg?: any): (boolean | K)[][]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((k: K = neverk) => [k: K = neverk, true])))