(
options: {
readonly oldValue: HashMap.HashMap<Key, Value>
readonly newValue: HashMap.HashMap<Key, Value>
readonly differ: Differ.Differ<Value, Patch>
}
)
| 115 | |
| 116 | /** @internal */ |
| 117 | export 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 */ |
| 152 | export const combine = Dual.dual< |
nothing calls this directly
no test coverage detected
searching dependent graphs…