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

Unified Diff: pkg/barback/lib/src/utils.dart

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 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 | « pkg/barback/lib/src/transformer.dart ('k') | pkg/barback/test/package_graph/lazy_transformer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/utils.dart
diff --git a/pkg/barback/lib/src/utils.dart b/pkg/barback/lib/src/utils.dart
index f1bcddde7f45085a1e977c5c1d5b03ea1653f07f..59c9d4b5375c16ff80c9d5b91cd8378da7e21284 100644
--- a/pkg/barback/lib/src/utils.dart
+++ b/pkg/barback/lib/src/utils.dart
@@ -140,10 +140,24 @@ List flatten(Iterable nested) {
Set unionAll(Iterable<Set> sets) =>
sets.fold(new Set(), (union, set) => union.union(set));
-/// Passes each key/value pair in [map] to [fn] and returns a new [Map] whose
-/// values are the return values of [fn].
-Map mapMapValues(Map map, fn(key, value)) =>
- new Map.fromIterable(map.keys, value: (key) => fn(key, map[key]));
+/// Creates a new map from [map] with new keys and values.
+///
+/// The return values of [keyFn] are used as the keys and the return values of
+/// [valueFn] are used as the values for the new map.
+Map mapMap(Map map, keyFn(key, value), valueFn(key, value)) =>
+ new Map.fromIterable(map.keys,
+ key: (key) => keyFn(key, map[key]),
+ value: (key) => valueFn(key, map[key]));
+
+/// Creates a new map from [map] with the same keys.
+///
+/// The return values of [fn] are used as the values for the new map.
+Map mapMapValues(Map map, fn(key, value)) => mapMap(map, (key, _) => key, fn);
+
+/// Creates a new map from [map] with the same keys.
+///
+/// The return values of [fn] are used as the keys for the new map.
+Map mapMapKeys(Map map, fn(key, value)) => mapMap(map, fn, (_, value) => value);
/// Returns whether [set1] has exactly the same elements as [set2].
bool setEquals(Set set1, Set set2) =>
« no previous file with comments | « pkg/barback/lib/src/transformer.dart ('k') | pkg/barback/test/package_graph/lazy_transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698