Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Copied over methods from Deki that should be available in DReAM instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorg committed Jul 30, 2015
1 parent 9f805f4 commit 2e70142
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/mindtouch.dream/system/Collections/Generic/DictionaryUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,34 @@ public static class DictionaryUtil {
}
return result;
}

public static IEnumerable<TValue> CollectAllValues<TKey, TValue>(this IDictionary<TKey, ICollection<TValue>> dictionary, IEnumerable<TKey> keys, out IEnumerable<TKey> missing) {
var result = new List<TValue>();
var missingResult = new List<TKey>();
foreach(var key in keys) {
ICollection<TValue> value;
if(dictionary.TryGetValue(key, out value)) {
result.AddRange(value);
} else {
missingResult.Add(key);
}
}
missing = missingResult;
return result;
}

public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, bool overwriteDuplicates = false) {
var result = new Dictionary<TKey, TValue>();
if(overwriteDuplicates) {
foreach(var pair in source) {
result[pair.Key] = pair.Value;
}
} else {
foreach(var pair in source) {
result.Add(pair.Key, pair.Value);
}
}
return result;
}
}
}

0 comments on commit 2e70142

Please sign in to comment.