Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Unified Diff: lib/src/utils.dart

Issue 1691173002: Support tag configuration. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/runner/configuration/load.dart ('k') | lib/test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 8c643eb64685a1841664adec1c4758b5ad3063aa..da3f9af494b25bc1676edcf09b3a93cde0b66988 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -202,16 +202,36 @@ List flatten(Iterable nested) {
return result;
}
-/// Returns a new map with all values in both [map1] and [map2].
+/// Creates a new map from [map] with new keys and values.
+///
+/// The return values of [key] are used as the keys and the return values of
+/// [value] are used as the values for the new map.
///
-/// If there are conflicting keys, [map2]'s value wins.
-Map mergeMaps(Map map1, Map map2) {
+/// [key] defaults to returning the original key and [value] defaults to
+/// returning the original value.
+Map mapMap(Map map, {key(key, value), value(key, value)}) {
+ if (key == null) key = (key, _) => key;
+ if (value == null) value = (_, value) => value;
+
var result = {};
- map1.forEach((key, value) {
- result[key] = value;
+ map.forEach((mapKey, mapValue) {
+ result[key(mapKey, mapValue)] = value(mapKey, mapValue);
});
+ return result;
+}
+
+/// Returns a new map with all values in both [map1] and [map2].
+///
+/// If there are conflicting keys, [value] is used to merge them. If it's
+/// not passed, [map2]'s value wins.
+Map mergeMaps(Map map1, Map map2, {value(value1, value2)}) {
+ var result = new Map.from(map1);
map2.forEach((key, value) {
- result[key] = value;
+ if (value == null || !result.containsKey(key)) {
+ result[key] = value;
+ } else {
+ result[key] = value(result[key], value);
+ }
});
return result;
}
« no previous file with comments | « lib/src/runner/configuration/load.dart ('k') | lib/test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698