<K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>Removes all key-value pairs from the MutableHashMap, mutating the map in place. The map becomes empty after this operation.
When to use
Use to empty a mutable hash map while keeping the same map instance.
Example (Clearing all entries)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["key1", 42],
["key2", 100],
["key3", 200]
)
console.log(MutableHashMap.size(map)) // 3
// Clear all entries
MutableHashMap.clear(map)
console.log(MutableHashMap.size(map)) // 0
console.log(MutableHashMap.has(map, "key1")) // false
// Can still add new entries after clearing
MutableHashMap.set(map, "new", 999)
console.log(MutableHashMap.size(map)) // 1export const const clear: <K, V>(
self: MutableHashMap<K, V>
) => MutableHashMap<K, V>
Removes all key-value pairs from the MutableHashMap, mutating the map in place.
The map becomes empty after this operation.
When to use
Use to empty a mutable hash map while keeping the same map instance.
Example (Clearing all entries)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["key1", 42],
["key2", 100],
["key3", 200]
)
console.log(MutableHashMap.size(map)) // 3
// Clear all entries
MutableHashMap.clear(map)
console.log(MutableHashMap.size(map)) // 0
console.log(MutableHashMap.has(map, "key1")) // false
// Can still add new entries after clearing
MutableHashMap.set(map, "new", 999)
console.log(MutableHashMap.size(map)) // 1
clear = <function (type parameter) K in <K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>(self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface MutableHashMap<out K, out V>A mutable hash map that stores key-value pairs and supports both referential
and Effect structural equality.
When to use
Use as a mutable key-value map when in-place updates are acceptable and keys
may rely on Effect structural equality.
Details
Operations mutate the map in place. Keys that implement Equal / Hash can
be looked up structurally; other keys use normal JavaScript reference or
primitive equality.
Example (Using a mutable hash map)
import { MutableHashMap } from "effect"
// Create a mutable hash map with string keys and number values
const map: MutableHashMap.MutableHashMap<string, number> = MutableHashMap
.empty()
// Add some data
MutableHashMap.set(map, "count", 42)
MutableHashMap.set(map, "total", 100)
// Use as iterable
for (const [key, value] of map) {
console.log(`${key}: ${value}`)
}
// Output:
// count: 42
// total: 100
// Convert to array
const entries = Array.from(map)
console.log(entries) // [["count", 42], ["total", 100]]
MutableHashMap<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>) => {
self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.MutableHashMap<K, V>.backing: Map<K, V>backing.Map<K, V>.clear(): voidclear()
self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.MutableHashMap<K, V>.buckets: Map<number, NonEmptyArray<K>>buckets.Map<number, [K, ...K[]]>.clear(): voidclear()
return self: MutableHashMap<K, V>(parameter) self: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self
}