Created
January 28, 2014 21:50
-
-
Save btjake/8677235 to your computer and use it in GitHub Desktop.
A curry (sorta) function for adding/updating a Dictionary<TKey, List<TValue>>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static Action<TKey, TValue> CurryAddUpdate<TKey,TValue>(this Dictionary<TKey, List<TValue>> dict) | |
{ | |
Action<TKey, TValue> op = (key, val) => { | |
if(dict.ContainsKey(key)) | |
{ | |
dict[key].Add(val); | |
} else { | |
dict.Add(key, new List<TValue>(new TValue[]{val})); | |
} | |
}; | |
return op; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment