Skip to content

Instantly share code, notes, and snippets.

@btjake
Created January 28, 2014 21:50
Show Gist options
  • Save btjake/8677235 to your computer and use it in GitHub Desktop.
Save btjake/8677235 to your computer and use it in GitHub Desktop.
A curry (sorta) function for adding/updating a Dictionary<TKey, List<TValue>>
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