Package: effect
Module: Newtype
Lifts an Equivalence for the carrier type into an Equivalence for the
newtype.
When to use
Use when you need equality for newtype-wrapped values to behave like equality for the wrapped carrier value, without manually unwrapping.
Details
The returned equivalence delegates to the provided carrier equivalence and has zero runtime cost beyond the underlying equivalence check.
Example (Comparing newtypes)
import { Equivalence, Newtype } from "effect"
interface Label extends Newtype.Newtype<"Label", string> {}
const eq = Newtype.makeEquivalence<Label>(Equivalence.String)
const iso = Newtype.makeIso<Label>()
eq(iso.set("a"), iso.set("a")) // true
eq(iso.set("a"), iso.set("b")) // false
See
makeOrder — lift an Order for the carrierSignature
declare const makeEquivalence: <N extends Newtype.Any>(equivalence: Equivalence.Equivalence<Newtype.Carrier<N>>) => Equivalence.Equivalence<N>
Since v4.0.0