I want to find a union of two dictionaries, that may contain the same keys, but different values. If key exists in both dictionaries, then I want to merge the values (if they differ) into list. If key exists in only one dictionary, then I want to create a List and add that item to it.
So, for example:
var dict1 = new Dictionary<int, string>();
var dict2 = new Dictionary<int, string>();
dict1.Add(1, "a");
dict2.Add(1, "b");
dict1.Add(2, "c");
var resultDict = Combine(dict1, dict2);
Result dictionary will be the type of Dictionary<int, List>, and will contain { 1: ["a", "b"], 2: ["c"]}.
The simplest solution I can think of, is to traverse union of keys and add empty lists, then traverse both dictionaries and add all values to list for given keys.
Is there any good, functional solution to combine these two Dictionaries?