| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.utils; | 5 library barback.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 /// A pair of values. | 9 /// A pair of values. |
| 10 class Pair<E, F> { | 10 class Pair<E, F> { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 assert(byte >= 0 && byte <= 255); | 76 assert(byte >= 0 && byte <= 255); |
| 77 | 77 |
| 78 const DIGITS = "0123456789abcdef"; | 78 const DIGITS = "0123456789abcdef"; |
| 79 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; | 79 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 /// Group the elements in [iter] by the value returned by [fn]. | 82 /// Group the elements in [iter] by the value returned by [fn]. |
| 83 /// | 83 /// |
| 84 /// This returns a map whose keys are the return values of [fn] and whose values | 84 /// This returns a map whose keys are the return values of [fn] and whose values |
| 85 /// are lists of each element in [iter] for which [fn] returned that key. | 85 /// are lists of each element in [iter] for which [fn] returned that key. |
| 86 Map groupBy(Iterable iter, fn(element)) { | 86 Map<Object, List> groupBy(Iterable iter, fn(element)) { |
| 87 var map = {}; | 87 var map = {}; |
| 88 for (var element in iter) { | 88 for (var element in iter) { |
| 89 var list = map.putIfAbsent(fn(element), () => []); | 89 var list = map.putIfAbsent(fn(element), () => []); |
| 90 list.add(element); | 90 list.add(element); |
| 91 } | 91 } |
| 92 return map; | 92 return map; |
| 93 } | 93 } |
| 94 | 94 |
| 95 /// Flattens nested lists inside an iterable into a single list containing only | 95 /// Flattens nested lists inside an iterable into a single list containing only |
| 96 /// non-list elements. | 96 /// non-list elements. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 stream.listen( | 189 stream.listen( |
| 190 controller.add, | 190 controller.add, |
| 191 onError: (error) => controller.addError(error), | 191 onError: (error) => controller.addError(error), |
| 192 onDone: controller.close); | 192 onDone: controller.close); |
| 193 }).catchError((e) { | 193 }).catchError((e) { |
| 194 controller.addError(e); | 194 controller.addError(e); |
| 195 controller.close(); | 195 controller.close(); |
| 196 }); | 196 }); |
| 197 return controller.stream; | 197 return controller.stream; |
| 198 } | 198 } |
| OLD | NEW |