( map1: HashMap.HashMap<string, ReadonlyArray<string>>, map2: ReadonlyArray<[string, ReadonlyArray<string>]> )
| 2020 | * Sums the list associated with the same key. |
| 2021 | */ |
| 2022 | const merge = ( |
| 2023 | map1: HashMap.HashMap<string, ReadonlyArray<string>>, |
| 2024 | map2: ReadonlyArray<[string, ReadonlyArray<string>]> |
| 2025 | ): HashMap.HashMap<string, ReadonlyArray<string>> => { |
| 2026 | if (Arr.isNonEmptyReadonlyArray(map2)) { |
| 2027 | const head = Arr.headNonEmpty(map2) |
| 2028 | const tail = Arr.tailNonEmpty(map2) |
| 2029 | const newMap = Option.match(HashMap.get(map1, head[0]), { |
| 2030 | onNone: () => HashMap.set(map1, head[0], head[1]), |
| 2031 | onSome: (elems) => HashMap.set(map1, head[0], Arr.appendAll(elems, head[1])) |
| 2032 | }) |
| 2033 | return merge(newMap, tail) |
| 2034 | } |
| 2035 | return map1 |
| 2036 | } |
| 2037 | |
| 2038 | // ============================================================================= |
| 2039 | // Completion Internals |
no test coverage detected