MCPcopy Index your code
hub / github.com/Effect-TS/effect / diff

Function diff

packages/effect/src/internal/differ/readonlyArrayPatch.ts:116–141  ·  view source on GitHub ↗
(
  options: {
    readonly oldValue: ReadonlyArray<Value>
    readonly newValue: ReadonlyArray<Value>
    readonly differ: Differ.Differ<Value, Patch>
  }
)

Source from the content-addressed store, hash-verified

114
115/** @internal */
116export const diff = <Value, Patch>(
117 options: {
118 readonly oldValue: ReadonlyArray<Value>
119 readonly newValue: ReadonlyArray<Value>
120 readonly differ: Differ.Differ<Value, Patch>
121 }
122): Differ.Differ.ReadonlyArray.Patch<Value, Patch> => {
123 let i = 0
124 let patch = empty<Value, Patch>()
125 while (i < options.oldValue.length && i < options.newValue.length) {
126 const oldElement = options.oldValue[i]!
127 const newElement = options.newValue[i]!
128 const valuePatch = options.differ.diff(oldElement, newElement)
129 if (!Equal.equals(valuePatch, options.differ.empty)) {
130 patch = combine(patch, makeUpdate(i, valuePatch))
131 }
132 i = i + 1
133 }
134 if (i < options.oldValue.length) {
135 patch = combine(patch, makeSlice(0, i))
136 }
137 if (i < options.newValue.length) {
138 patch = combine(patch, makeAppend(Arr.drop(i)(options.newValue)))
139 }
140 return patch
141}
142
143/** @internal */
144export const combine = Dual.dual<

Callers

nothing calls this directly

Calls 6

emptyFunction · 0.70
makeUpdateFunction · 0.70
makeSliceFunction · 0.70
makeAppendFunction · 0.70
diffMethod · 0.65
combineFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…