| 154 | |
| 155 | /** @internal */ |
| 156 | export const diff = ( |
| 157 | oldValue: Supervisor.Supervisor<any>, |
| 158 | newValue: Supervisor.Supervisor<any> |
| 159 | ): SupervisorPatch => { |
| 160 | if (Equal.equals(oldValue, newValue)) { |
| 161 | return empty |
| 162 | } |
| 163 | const oldSupervisors = toSet(oldValue) |
| 164 | const newSupervisors = toSet(newValue) |
| 165 | const added = pipe( |
| 166 | newSupervisors, |
| 167 | HashSet.difference(oldSupervisors), |
| 168 | HashSet.reduce( |
| 169 | empty as SupervisorPatch, |
| 170 | (patch, supervisor) => combine(patch, { _tag: OP_ADD_SUPERVISOR, supervisor }) |
| 171 | ) |
| 172 | ) |
| 173 | const removed = pipe( |
| 174 | oldSupervisors, |
| 175 | HashSet.difference(newSupervisors), |
| 176 | HashSet.reduce( |
| 177 | empty as SupervisorPatch, |
| 178 | (patch, supervisor) => combine(patch, { _tag: OP_REMOVE_SUPERVISOR, supervisor }) |
| 179 | ) |
| 180 | ) |
| 181 | return combine(added, removed) |
| 182 | } |
| 183 | |
| 184 | /** @internal */ |
| 185 | export const differ = Differ.make<Supervisor.Supervisor<any>, SupervisorPatch>({ |