I need merge maps mapA andmapB with pairs of \"name\" - \"phone number\" into the final map, sticking together the values for duplicate keys, separated
mapA
mapB
I would write something like
fun Map.mergeWith(another: Map): Map { val unionList: MutableMap = toMutableMap() for ((key, value) in another) { unionList[key] = listOfNotNull(unionList[key], value).toSet().joinToString(", ") } return unionList } val mergedMap = mapA.mergeWith(mapB)