<K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>
<K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>Removes the specified key from the MutableHashMap, mutating the map in place. If the key doesn't exist, the map remains unchanged.
When to use
Use to delete one key from a mutable hash map in place.
Example (Removing a key)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["key1", 42],
["key2", 100],
["key3", 200]
)
console.log(MutableHashMap.size(map)) // 3
// Remove existing key
MutableHashMap.remove(map, "key2")
console.log(MutableHashMap.size(map)) // 2
console.log(MutableHashMap.has(map, "key2")) // false
// Remove non-existent key (no effect)
MutableHashMap.remove(map, "nonexistent")
console.log(MutableHashMap.size(map)) // 2
// Pipe-able version
const removeKey = MutableHashMap.remove("key1")
removeKey(map)
console.log(MutableHashMap.size(map)) // 1export const const remove: {
<K>(key: K): <V>(
self: MutableHashMap<K, V>
) => MutableHashMap<K, V>
<K, V>(
self: MutableHashMap<K, V>,
key: K
): MutableHashMap<K, V>
}
Removes the specified key from the MutableHashMap, mutating the map in place.
If the key doesn't exist, the map remains unchanged.
When to use
Use to delete one key from a mutable hash map in place.
Example (Removing a key)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["key1", 42],
["key2", 100],
["key3", 200]
)
console.log(MutableHashMap.size(map)) // 3
// Remove existing key
MutableHashMap.remove(map, "key2")
console.log(MutableHashMap.size(map)) // 2
console.log(MutableHashMap.has(map, "key2")) // false
// Remove non-existent key (no effect)
MutableHashMap.remove(map, "nonexistent")
console.log(MutableHashMap.size(map)) // 2
// Pipe-able version
const removeKey = MutableHashMap.remove("key1")
removeKey(map)
console.log(MutableHashMap.size(map)) // 1
remove: {
<function (type parameter) K in <K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K>(key: Kkey: function (type parameter) K in <K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K): <function (type parameter) V in <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>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K, function (type parameter) V in <V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>) => 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>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K, function (type parameter) V in <V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>
<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): 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>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>V>, key: Kkey: function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>K): 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>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>V>
} = dual<<K>(key: K) => <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>, <K, V>(self: MutableHashMap<K, V>, key: K) => MutableHashMap<K, V>>(arity: 2, body: <K, V>(self: MutableHashMap<K, V>, key: K) => MutableHashMap<K, V>): (<K>(key: K) => <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>) & (<K, V>(self: MutableHashMap<K, V>, key: K) => MutableHashMap<K, V>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual<
<function (type parameter) K in <K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K>(key: Kkey: function (type parameter) K in <K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K) => <function (type parameter) V in <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>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K, function (type parameter) V in <V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>) => 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>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>K, function (type parameter) V in <V>(self: MutableHashMap<K, V>): MutableHashMap<K, V>V>,
<function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): 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>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>V>, key: Kkey: function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>K) => 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>, key: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>V>
>(2, <function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key_: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key_: K): 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>, key_: K): MutableHashMap<K, V>K, function (type parameter) V in <K, V>(self: MutableHashMap<K, V>, key_: K): MutableHashMap<K, V>V>, key_: Kkey_: function (type parameter) K in <K, V>(self: MutableHashMap<K, V>, key_: K): MutableHashMap<K, V>K) => {
if (const isSimpleKey: (u: unknown) => booleanisSimpleKey(key_: Kkey_)) {
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>.delete(key: K): booleandelete(key_: Kkey_)
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
}
const const key: anykey = const referentialKeysCache: WeakMap<
any,
any
>
referentialKeysCache.WeakMap<any, any>.get(key: any): anyget(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) ?? key_: Kkey_
const const hash: numberhash = import HashHash.const hash: <any>(self: any) => numberComputes a hash value for any given value.
When to use
Use to compute an Effect hash for primitives, collections, and hashable
objects.
Details
This function can hash primitives (numbers, strings, booleans, etc.) as well as
objects, arrays, and other complex data structures. It automatically handles
different types and provides a consistent hash value for equivalent inputs.
Gotchas
Objects being hashed must be treated as immutable after their first hash
computation. Hash results are cached, so mutating an object after hashing will
lead to stale cached values and broken hash-based operations. For mutable
objects, implement a custom Hash interface that hashes the object reference
rather than its content.
Example (Hashing different values)
import { Hash } from "effect"
// Hash primitive values
console.log(Hash.hash(42)) // numeric hash
console.log(Hash.hash("hello")) // string hash
console.log(Hash.hash(true)) // boolean hash
// Hash objects and arrays
console.log(Hash.hash({ name: "John", age: 30 }))
console.log(Hash.hash([1, 2, 3]))
console.log(Hash.hash({ id: "user-1", roles: ["admin", "editor"] }))
hash(const key: anykey)
const const bucket: [K, ...K[]] | undefinedbucket = 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[]]>.get(key: number): [K, ...K[]] | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(const hash: numberhash)
if (const bucket: [K, ...K[]] | undefinedbucket === var undefinedundefined) {
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
}
for (let let i: numberi = 0, let len: numberlen = const bucket: [K, ...K[]]const bucket: {
0: K;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => K | undefined;
push: (...items: Array<K>) => number;
concat: { (...items: Array<ConcatArray<K>>): Array<K>; (...items: Array<K | ConcatArray<K>>): Array<K> };
join: (separator?: string) => string;
reverse: () => Array<K>;
shift: () => K | undefined;
slice: (start?: number, end?: number) => Array<K>;
sort: (compareFn?: ((a: K, b: K) => number) | undefined) => [K, ...K[]];
splice: { (start: number, deleteCount?: number): Array<K>; (start: number, deleteCount: number, ...items: Array<K>): Array<K> };
unshift: (...items: Array<K>) => number;
indexOf: (searchElement: K, fromIndex?: number) => number;
lastIndexOf: (searchElement: K, fromIndex?: number) => number;
every: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): this is S[]; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: K, index: number, array: Array<K>) => void, thisArg?: any) => void;
map: (callbackfn: (value: K, index: number, array: Array<K>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): Array<S>; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): Array<K> };
reduce: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
find: { (predicate: (value: K, index: number, obj: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any): K | undefined };
findIndex: (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any) => number;
fill: (value: K, start?: number, end?: number) => [K, ...K[]];
copyWithin: (target: number, start: number, end?: number) => [K, ...K[]];
entries: () => ArrayIterator<[number, K]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<K>;
includes: (searchElement: K, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: K, index: number, array: Array<K>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => K | undefined;
findLast: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): K | undefined };
findLastIndex: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => number;
toReversed: () => Array<K>;
toSorted: (compareFn?: ((a: K, b: K) => number) | undefined) => Array<K>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<K>): Array<K>; (start: number, deleteCount?: number): Array<K> };
with: (index: number, value: K) => Array<K>;
}
bucket.length: numberlength; let i: numberi < let len: numberlen; let i: numberi++) {
const const bkey: Kbkey = const bucket: [K, ...K[]]const bucket: {
0: K;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => K | undefined;
push: (...items: Array<K>) => number;
concat: { (...items: Array<ConcatArray<K>>): Array<K>; (...items: Array<K | ConcatArray<K>>): Array<K> };
join: (separator?: string) => string;
reverse: () => Array<K>;
shift: () => K | undefined;
slice: (start?: number, end?: number) => Array<K>;
sort: (compareFn?: ((a: K, b: K) => number) | undefined) => [K, ...K[]];
splice: { (start: number, deleteCount?: number): Array<K>; (start: number, deleteCount: number, ...items: Array<K>): Array<K> };
unshift: (...items: Array<K>) => number;
indexOf: (searchElement: K, fromIndex?: number) => number;
lastIndexOf: (searchElement: K, fromIndex?: number) => number;
every: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): this is S[]; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: K, index: number, array: Array<K>) => void, thisArg?: any) => void;
map: (callbackfn: (value: K, index: number, array: Array<K>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): Array<S>; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): Array<K> };
reduce: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
find: { (predicate: (value: K, index: number, obj: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any): K | undefined };
findIndex: (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any) => number;
fill: (value: K, start?: number, end?: number) => [K, ...K[]];
copyWithin: (target: number, start: number, end?: number) => [K, ...K[]];
entries: () => ArrayIterator<[number, K]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<K>;
includes: (searchElement: K, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: K, index: number, array: Array<K>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => K | undefined;
findLast: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): K | undefined };
findLastIndex: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => number;
toReversed: () => Array<K>;
toSorted: (compareFn?: ((a: K, b: K) => number) | undefined) => Array<K>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<K>): Array<K>; (start: number, deleteCount?: number): Array<K> };
with: (index: number, value: K) => Array<K>;
}
bucket[let i: numberi]
if (const bkey: Kbkey === const key: anykey || import EqualEqual.function equals<any, K>(self: any, that: K): boolean (+1 overload)Checks whether two values are deeply structurally equal.
When to use
Use when you need Effect's default structural equality check.
Details
Returns a boolean and never throws. Primitives are compared by value, and
NaN equals NaN. Objects implementing Equal delegate to their
[Equal.symbol] method; if only one operand implements Equal, the result
is false.
Dates compare by ISO string, RegExps compare by string representation,
arrays compare element-by-element, Maps and Sets compare entries
order-independently, and plain objects compare enumerable keys recursively.
Functions without an Equal implementation compare by reference. Circular
references are handled when both structures are circular at the same depth.
Hash values are checked first as a fast-path rejection. The function also
supports dual data-last usage: call it with one argument to get a curried
predicate.
Gotchas
- Results are cached per object pair in a WeakMap. Objects must not be
mutated after their first comparison.
- Map and Set comparisons are O(n²) in size.
Example (Comparing values)
import { Equal } from "effect"
// Primitives
console.log(Equal.equals(1, 1)) // true
console.log(Equal.equals(NaN, NaN)) // true
console.log(Equal.equals("a", "b")) // false
// Objects and arrays
console.log(Equal.equals({ a: 1, b: 2 }, { a: 1, b: 2 })) // true
console.log(Equal.equals([1, [2, 3]], [1, [2, 3]])) // true
// Dates
console.log(Equal.equals(new Date("2024-01-01"), new Date("2024-01-01"))) // true
// Maps (order-independent)
const m1 = new Map([["a", 1], ["b", 2]])
const m2 = new Map([["b", 2], ["a", 1]])
console.log(Equal.equals(m1, m2)) // true
// Curried form
const is5 = Equal.equals(5)
console.log(is5(5)) // true
console.log(is5(3)) // false
equals(const key: anykey, const bkey: Kbkey)) {
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>.delete(key: K): booleandelete(const bkey: Kbkey)
const bucket: [K, ...K[]]const bucket: {
0: K;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => K | undefined;
push: (...items: Array<K>) => number;
concat: { (...items: Array<ConcatArray<K>>): Array<K>; (...items: Array<K | ConcatArray<K>>): Array<K> };
join: (separator?: string) => string;
reverse: () => Array<K>;
shift: () => K | undefined;
slice: (start?: number, end?: number) => Array<K>;
sort: (compareFn?: ((a: K, b: K) => number) | undefined) => [K, ...K[]];
splice: { (start: number, deleteCount?: number): Array<K>; (start: number, deleteCount: number, ...items: Array<K>): Array<K> };
unshift: (...items: Array<K>) => number;
indexOf: (searchElement: K, fromIndex?: number) => number;
lastIndexOf: (searchElement: K, fromIndex?: number) => number;
every: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): this is S[]; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: K, index: number, array: Array<K>) => void, thisArg?: any) => void;
map: (callbackfn: (value: K, index: number, array: Array<K>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): Array<S>; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): Array<K> };
reduce: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
find: { (predicate: (value: K, index: number, obj: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any): K | undefined };
findIndex: (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any) => number;
fill: (value: K, start?: number, end?: number) => [K, ...K[]];
copyWithin: (target: number, start: number, end?: number) => [K, ...K[]];
entries: () => ArrayIterator<[number, K]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<K>;
includes: (searchElement: K, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: K, index: number, array: Array<K>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => K | undefined;
findLast: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): K | undefined };
findLastIndex: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => number;
toReversed: () => Array<K>;
toSorted: (compareFn?: ((a: K, b: K) => number) | undefined) => Array<K>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<K>): Array<K>; (start: number, deleteCount?: number): Array<K> };
with: (index: number, value: K) => Array<K>;
}
bucket.Array<K>.splice(start: number, deleteCount?: number): K[] (+1 overload)Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
splice(let i: numberi, 1)
break
}
}
if (const bucket: [K, ...K[]]const bucket: {
0: K;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => K | undefined;
push: (...items: Array<K>) => number;
concat: { (...items: Array<ConcatArray<K>>): Array<K>; (...items: Array<K | ConcatArray<K>>): Array<K> };
join: (separator?: string) => string;
reverse: () => Array<K>;
shift: () => K | undefined;
slice: (start?: number, end?: number) => Array<K>;
sort: (compareFn?: ((a: K, b: K) => number) | undefined) => [K, ...K[]];
splice: { (start: number, deleteCount?: number): Array<K>; (start: number, deleteCount: number, ...items: Array<K>): Array<K> };
unshift: (...items: Array<K>) => number;
indexOf: (searchElement: K, fromIndex?: number) => number;
lastIndexOf: (searchElement: K, fromIndex?: number) => number;
every: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): this is S[]; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: K, index: number, array: Array<K>) => void, thisArg?: any) => void;
map: (callbackfn: (value: K, index: number, array: Array<K>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): Array<S>; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): Array<K> };
reduce: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K): K; (callbackfn: (previousValue: K, currentValue: K, currentIndex: number, array: Array<K>) => K, initialValue: K): K; (callbackfn: (previousVa…;
find: { (predicate: (value: K, index: number, obj: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any): K | undefined };
findIndex: (predicate: (value: K, index: number, obj: Array<K>) => unknown, thisArg?: any) => number;
fill: (value: K, start?: number, end?: number) => [K, ...K[]];
copyWithin: (target: number, start: number, end?: number) => [K, ...K[]];
entries: () => ArrayIterator<[number, K]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<K>;
includes: (searchElement: K, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: K, index: number, array: Array<K>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => K | undefined;
findLast: { (predicate: (value: K, index: number, array: Array<K>) => value is S, thisArg?: any): S | undefined; (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any): K | undefined };
findLastIndex: (predicate: (value: K, index: number, array: Array<K>) => unknown, thisArg?: any) => number;
toReversed: () => Array<K>;
toSorted: (compareFn?: ((a: K, b: K) => number) | undefined) => Array<K>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<K>): Array<K>; (start: number, deleteCount?: number): Array<K> };
with: (index: number, value: K) => Array<K>;
}
bucket.length: numberlength === 0) {
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[]]>.delete(key: number): booleandelete(const hash: numberhash)
}
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
})