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

Unified Diff: frog/utils.dart

Issue 8618006: Warnings for instantiating an abstract type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « frog/type.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/utils.dart
diff --git a/frog/utils.dart b/frog/utils.dart
index 657349a6cf0c7d20ca3ed3c89286791ad5b32128..cb3ca2627c0a682b78a71af7f8d99abf6f1270f7 100644
--- a/frog/utils.dart
+++ b/frog/utils.dart
@@ -7,8 +7,8 @@
// TODO(jmesserly): we might want a version of this that return an iterable,
// however JS, Python and Ruby versions are all eager.
-List map(Iterable source, mapper(source)) {
- List result = new List();
+List map(Iterable source, Dynamic mapper(source)) {
+ List result = [];
if (source is List) {
List list = source; // TODO: shouldn't need this
result.length = list.length;
@@ -36,8 +36,8 @@ reduce(Iterable source, callback, [initialValue]) {
return current;
}
-List zip(Iterable left, Iterable right, mapper(left, right)) {
- List result = new List();
+List zip(Iterable left, Iterable right, Dynamic mapper(left, right)) {
+ List result = [];
var x = left.iterator();
var y = right.iterator();
while (x.hasNext() && y.hasNext()) {
@@ -49,6 +49,16 @@ List zip(Iterable left, Iterable right, mapper(left, right)) {
return result;
}
+Map<Dynamic, List> groupBy(Iterable left, Dynamic keyFn(value)) {
+ Map result = {};
+ var iter = left.iterator();
+ while (iter.hasNext()) {
+ var i = iter.next();
+ result.putIfAbsent(keyFn(i), () => []).add(i);
+ }
+ return result;
+}
+
/** Sorts the map by the key. */
List orderValuesByKeys(Map map) {
// TODO(jmesserly): it'd be nice to have SortedMap in corelib.
« no previous file with comments | « frog/type.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698