Chromium Code Reviews| Index: utils/pub/utils.dart |
| diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart |
| index 7710ac194a1691e2da88c94fad9f780979d93f07..e283a2e02cd2d0036c3e54b1dbb7f384ce3425ae 100644 |
| --- a/utils/pub/utils.dart |
| +++ b/utils/pub/utils.dart |
| @@ -118,6 +118,18 @@ void chainToCompleter(Future future, Completer completer) { |
| onError: (e) => completer.completeError(e.error, e.stackTrace)); |
| } |
| +/// Like [Iterable.where], but allows [test] to return [Future]s and uses the |
| +/// results of those [Future]s as the test. |
| +Future<Iterable> futureWhere(Iterable iter, test(value)) { |
| + return Future.wait(iter.mappedBy((e) { |
| + var result = test(e); |
| + if (result is! Future) result = new Future.immediate(result); |
| + return result.then((result) => new Pair(e, result)); |
| + })) |
| + .then((pairs) => pairs.where((pair) => pair.last)) |
| + .then((pairs) => pairs.mappedBy((pair) => pair.first)); |
| +} |
|
Bob Nystrom
2013/01/31 18:54:54
It took me a surprisingly long while to tease apar
nweiz
2013/01/31 20:31:54
Doing that makes the code using this worse. I thin
|
| + |
| // TODO(nweiz): unify the following functions with the utility functions in |
| // pkg/http. |