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

Unified Diff: pkg/serialization/lib/src/serialization_helpers.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/serialization/lib/src/reader_writer.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/serialization_helpers.dart
diff --git a/pkg/serialization/lib/src/serialization_helpers.dart b/pkg/serialization/lib/src/serialization_helpers.dart
index 335bc0d475297ba09bd3af5e05b55c6cba057237..407c6562d2b765f6c5c5553e9f6e371672b3196b 100644
--- a/pkg/serialization/lib/src/serialization_helpers.dart
+++ b/pkg/serialization/lib/src/serialization_helpers.dart
@@ -18,7 +18,7 @@ doNothing(x) => x;
/** Concatenate two lists. Handle the case where one or both might be null. */
// TODO(alanknight): Remove once issue 5342 is resolved.
-List append(List a, List b) {
+List append(Iterable a, Iterable b) {
if (a == null) {
return (b == null) ? [] : new List.from(b);
}
@@ -29,11 +29,11 @@ List append(List a, List b) {
}
/**
- * Return a sorted version of [aCollection], using the default sort criterion.
- * Always returns a List, regardless of the type of [aCollection].
+ * Return a sorted version of [anIterable], using the default sort criterion.
+ * Always returns a List, regardless of the type of [anIterable].
*/
-List sorted(aCollection) {
- var result = new List.from(aCollection);
+List sorted(anIterable) {
+ var result = new List.from(anIterable);
result.sort();
return result;
}
@@ -105,9 +105,10 @@ class MapLikeIterableForList extends MapLikeIterable {
MapLikeIterableForList(collection) : super(collection);
void forEach(f) {
- Iterator iterator = collection.iterator();
+ Iterator iterator = collection.iterator;
for (var i = 0; i < collection.length; i++) {
- f(i, iterator.next());
+ iterator.moveNext();
+ f(i, iterator.current);
}
}
@@ -129,6 +130,13 @@ values(x) {
throw new ArgumentError("Invalid argument");
}
+mapValues(x, f) {
+ if (x is Set) return x.mappedBy(f).toSet();
+ if (x is Iterable) return x.mappedBy(f).toList();
+ if (x is Map) return new ListLikeIterable(x).map(f);
+ throw new ArgumentError("Invalid argument");
+}
+
/**
* A class for iterating over things as if they were Lists, which primarily
* means that forEach passes one argument, and map() returns a new Map
@@ -159,7 +167,7 @@ class ListLikeIterable {
/**
* Return an iterator that behaves like a List iterator, taking one parameter.
*/
- Iterator iterator() => collection.values.iterator();
+ Iterator get iterator => collection.values.iterator;
}
/**
« no previous file with comments | « pkg/serialization/lib/src/reader_writer.dart ('k') | pkg/serialization/lib/src/serialization_rule.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698