Difference Between `S.equivalence` and `Equal` Trait in Effect TS Library

Hi, is there are difference between S.equivalence and the way the Equal trait is implemented?

I'm following a suggestion from Mike from this Github issue: https://github.com/Effect-TS/effect/issues/4801

Since Effect's Cache module does not expose a way to control cache key comparison, he suggested to use Equal trait.

In our code base we use S.TaggedClass for most of our requests. Now I want to cache a request like this:

export class PaymentMatchRequest extends S.TaggedClass<PaymentMatchRequest>(
  "PaymentRevenueMatching/PaymentMatchRequest",
)("payment", {
  clientId: S.String,
  identifiers: S.Array(S.String),
  period: Period,
}) {}
Now S.equivalence` holds true for inputs:

const Eq = S.equivalence(PaymentMatchRequest);

const a = new PaymentMatchRequest({
  clientId: "foo",
  identifiers: ["bar"],
  period: { start: new Date("2025-01-01"), end: new Date("2025-01-02") },
});

const b = new PaymentMatchRequest({
  clientId: "foo",
  identifiers: ["bar"],
  period: { start: new Date("2025-01-01"), end: new Date("2025-01-02") },
});

const equals = Eq(a, b); // holds true
Was this page helpful?