<T extends object>(obj: T): TMarks an object permanently to use reference equality, without creating a proxy.
When to use
Use when you need reference equality without proxy allocation and accept permanently marking the original object for reference-only equality.
Details
- Adds
objto an internal WeakSet. From that point on, equals treats it as reference-only. - Returns the same object (not a copy or proxy), so
byReferenceUnsafe(x) === x. - Does not affect the object's prototype, properties, or behavior beyond equality checks.
Gotchas
The marking is irreversible for the lifetime of the object.
Example (Marking an object for reference equality)
import { Equal } from "effect"
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 1, b: 2 }
Equal.byReferenceUnsafe(obj1)
console.log(Equal.equals(obj1, obj2)) // false (reference)
console.log(Equal.equals(obj1, obj1)) // true (same reference)
console.log(obj1 === Equal.byReferenceUnsafe(obj1)) // true (same object)export const const byReferenceUnsafe: <
T extends object
>(
obj: T
) => T
Marks an object permanently to use reference equality, without creating a proxy.
When to use
Use when you need reference equality without proxy allocation and accept
permanently marking the original object for reference-only equality.
Details
-
Adds obj to an internal WeakSet. From that point on,
equals
treats it as reference-only.
-
Returns the same object (not a copy or proxy), so
byReferenceUnsafe(x) === x.
-
Does not affect the object's prototype, properties, or behavior
beyond equality checks.
Gotchas
The marking is irreversible for the lifetime of the object.
Example (Marking an object for reference equality)
import { Equal } from "effect"
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 1, b: 2 }
Equal.byReferenceUnsafe(obj1)
console.log(Equal.equals(obj1, obj2)) // false (reference)
console.log(Equal.equals(obj1, obj1)) // true (same reference)
console.log(obj1 === Equal.byReferenceUnsafe(obj1)) // true (same object)
byReferenceUnsafe = <function (type parameter) T in <T extends object>(obj: T): TT extends object>(obj: T extends objectobj: function (type parameter) T in <T extends object>(obj: T): TT): function (type parameter) T in <T extends object>(obj: T): TT => {
const byReferenceInstances: WeakSet<object>byReferenceInstances.WeakSet<object>.add(value: object): WeakSet<object>Appends a new value to the end of the WeakSet.
add(obj: T extends objectobj)
return obj: T extends objectobj
}