Package: effect
Module: Equal
Creates a proxy that uses reference equality instead of structural equality.
When to use
Use when you need to compare a plain object or array by identity without mutating the original value.
Details
Proxy wrapping obj. The proxy reads through to the
original, so property access is unchanged.equals returns
false for any pair where at least one operand is in that set (unless
they are the same reference).byReference(x) !== byReference(x).byReferenceUnsafe).Example (Opting out of structural equality)
import { Equal } from "effect"
const a = { x: 1 }
const b = { x: 1 }
console.log(Equal.equals(a, b)) // true (structural)
const aRef = Equal.byReference(a)
console.log(Equal.equals(aRef, b)) // false (reference)
console.log(Equal.equals(aRef, aRef)) // true (same reference)
console.log(aRef.x) // 1 (proxy reads through)
See
byReferenceUnsafe — same effect without a proxy (mutates the
original)equals — the comparison function affected by this opt-outSignature
declare const byReference: <T extends object>(obj: T) => T
Since v4.0.0