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

Function diff

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

Source from the content-addressed store, hash-verified

115
116/** @internal */
117export const diff = <Key, Value, Patch>(
118 options: {
119 readonly oldValue: HashMap.HashMap<Key, Value>
120 readonly newValue: HashMap.HashMap<Key, Value>
121 readonly differ: Differ.Differ<Value, Patch>
122 }
123): Differ.Differ.HashMap.Patch<Key, Value, Patch> => {
124 const [removed, patch] = HashMap.reduce(
125 [options.oldValue, empty<Key, Value, Patch>()] as const,
126 ([map, patch], newValue: Value, key: Key) => {
127 const option = HashMap.get(key)(map)
128 switch (option._tag) {
129 case "Some": {
130 const valuePatch = options.differ.diff(option.value, newValue)
131 if (Equal.equals(valuePatch, options.differ.empty)) {
132 return [HashMap.remove(key)(map), patch] as const
133 }
134 return [
135 HashMap.remove(key)(map),
136 combine<Key, Value, Patch>(makeUpdate(key, valuePatch))(patch)
137 ] as const
138 }
139 case "None": {
140 return [map, combine<Key, Value, Patch>(makeAdd(key, newValue))(patch)] as const
141 }
142 }
143 }
144 )(options.newValue)
145 return HashMap.reduce(
146 patch,
147 (patch, _, key: Key) => combine<Key, Value, Patch>(makeRemove(key))(patch)
148 )(removed)
149}
150
151/** @internal */
152export const combine = Dual.dual<

Callers

nothing calls this directly

Calls 8

emptyFunction · 0.70
makeUpdateFunction · 0.70
makeAddFunction · 0.70
makeRemoveFunction · 0.70
getMethod · 0.65
diffMethod · 0.65
removeMethod · 0.65
combineFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…