Chromium Code Reviews| Index: utils/pub/utils.dart |
| diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart |
| index cf9b456164996497779c7f188c998c36d4d84b75..9bcb3bdde90884e3d5918e43d9f34b08278adfb7 100644 |
| --- a/utils/pub/utils.dart |
| +++ b/utils/pub/utils.dart |
| @@ -18,4 +18,35 @@ String padRight(String source, int length) { |
| } |
| return result.toString(); |
| -} |
| +} |
| + |
| +/** |
| + * Runs [fn] after [future] completes, whether it completes successfully or not. |
| + * Essentially an asynchronous `finally` block. |
| + */ |
| +always(Future future, fn()) { |
|
Bob Nystrom
2012/05/03 00:15:49
I sketched out something like this once but didn't
nweiz
2012/05/04 01:03:43
I don't follow... what would these arguments do?
Bob Nystrom
2012/05/04 17:02:06
I don't know if this is a good idea, but for examp
nweiz
2012/05/07 18:28:35
I don't think that really adds any clarity.
|
| + var completer = new Completer(); |
| + future.then((_) => fn()); |
| + future.handleException((_) { |
| + fn(); |
| + return false; |
| + }); |
| +} |
| + |
| +/** |
| + * Flattens nested lists into a single list containing only non-list elements. |
| + */ |
| +List flatten(List nested) { |
| + var result = []; |
| + helper(list) { |
| + for (var e in list) { |
|
Bob Nystrom
2012/05/03 00:15:49
e -> element or item
Bob Nystrom
2012/05/03 00:15:49
"e" -> element or item
nweiz
2012/05/04 01:03:43
Done.
|
| + if (e is List) { |
|
Bob Nystrom
2012/05/03 00:15:49
Iterable?
nweiz
2012/05/04 01:03:43
That's how I had it originally, but I changed it t
Bob Nystrom
2012/05/04 17:02:06
I was thinking the same thing. Type tests are alwa
|
| + helper(e); |
| + } else { |
| + result.add(e); |
| + } |
| + } |
| + } |
| + helper(nested); |
| + return result; |
| +} |