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

Function diff

packages/effect/src/internal/differ/chunkPatch.ts:117–142  ·  view source on GitHub ↗
(
  options: {
    readonly oldValue: Chunk.Chunk<Value>
    readonly newValue: Chunk.Chunk<Value>
    readonly differ: Differ.Differ<Value, Patch>
  }
)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

unsafeGetMethod · 0.80
emptyFunction · 0.70
makeUpdateFunction · 0.70
makeSliceFunction · 0.70
makeAppendFunction · 0.70
diffMethod · 0.65
pipeFunction · 0.50
combineFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…