Diffing Two Records in Effect-TS: Is There a Built-In Method?

any better way to diff two records? is there a built in for this?

/**
 * Returns a new record containing only the keys where the values differ
 * between two input records. Only overlapping keys are compared.
 */
export const valueDifference: {
  <K1 extends string, A, B>(
    that: Record<K1, A>,
  ): <K2 extends string>(self: Record<K2, B>) => Record<Record.ReadonlyRecord.IntersectKeys<K1, K2>, A | B>;

  <K1 extends string, A, K2 extends string, B>(
    self: Record<K1, A>,
    that: Record<K2, B>,
  ): Record<Record.ReadonlyRecord.IntersectKeys<K1, K2>, A | B>;
} = dual(2, (self, that) =>
  Record.filter(
    Record.intersection(self, that, (a: unknown) => a),
    (value, key) => Record.has(that, key) && !Equal.equals(value, that[key]),
  ),
);
Was this page helpful?