import { EmptyOrPatch, SetLeftOrPatch, SetRightOrPatch, UpdateLeftOrPatch, UpdateRightOrPatch } from "@tsplus/stdlib/data/Differ/OrPatch/definition" /** * Constructs an `OrPatch` from a new and old value and a differ for the * values. * * @tsplus static Differ.Or.Patch.Ops diff */ export function diff( oldValue: Either, newValue: Either, left: Differ, right: Differ ): Differ.Or.Patch { switch (oldValue._tag) { case "Left": { switch (newValue._tag) { case "Left": { const valuePatch = left.diff(oldValue.left, newValue.left) if (Equals.equals(valuePatch, left.empty)) { return new EmptyOrPatch() } return new UpdateLeftOrPatch(valuePatch) } case "Right": { return new SetRightOrPatch(newValue.right) } } } case "Right": { switch (newValue._tag) { case "Left": { return new SetLeftOrPatch(newValue.left) } case "Right": { const valuePatch = right.diff(oldValue.right, newValue.right) if (Equals.equals(valuePatch, right.empty)) { return new EmptyOrPatch() } return new UpdateRightOrPatch(valuePatch) } } } } }