I need merge maps mapA
andmapB
with pairs of \"name\" - \"phone number\" into the final map, sticking together the values for duplicate keys, separated
Here's my solution:
val result = (mapA + (mapB - mapA.keys)).mapValues {
(setOf(it.value) + mapB[it.key]).filterNotNull().joinToString()
}
It creates a map of A plus the values from B that are not in A. Then it maps all values to a set and adds the value from B to that set, ultimately removing all null
values from the set and transforming it into a list, which you can use to create the desired output format.