Package: effect
Module: Equal
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
obj to an internal WeakSet. From that point on, equals
treats it as reference-only.byReferenceUnsafe(x) === x.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)
See
byReference — safer alternative that creates a proxyequals — the comparison function affected by this opt-outSignature
declare const byReferenceUnsafe: <T extends object>(obj: T) => T
Since v4.0.0