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 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
9 | 9 |
10 /// A pair of values. | 10 /// A pair of values. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 const DIGITS = "0123456789abcdef"; | 79 const DIGITS = "0123456789abcdef"; |
80 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; | 80 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; |
81 } | 81 } |
82 | 82 |
83 /// Converts [input] into a [Uint8List]. | 83 /// Converts [input] into a [Uint8List]. |
84 /// | 84 /// |
85 /// If [input] is a [TypedData], this just returns a view on [input]. | 85 /// If [input] is a [TypedData], this just returns a view on [input]. |
86 Uint8List toUint8List(List<int> input) { | 86 Uint8List toUint8List(List<int> input) { |
87 if (input is Uint8List) return input; | 87 if (input is Uint8List) return input; |
88 if (input is TypedData) return new Uint8List.view(input.buffer); | 88 if (input is TypedData) { |
| 89 // TODO(nweiz): remove "as" when issue 11080 is fixed. |
| 90 return new Uint8List.view((input as TypedData).buffer); |
| 91 } |
89 return new Uint8List.fromList(input); | 92 return new Uint8List.fromList(input); |
90 } | 93 } |
91 | 94 |
92 /// Group the elements in [iter] by the value returned by [fn]. | 95 /// Group the elements in [iter] by the value returned by [fn]. |
93 /// | 96 /// |
94 /// This returns a map whose keys are the return values of [fn] and whose values | 97 /// This returns a map whose keys are the return values of [fn] and whose values |
95 /// are lists of each element in [iter] for which [fn] returned that key. | 98 /// are lists of each element in [iter] for which [fn] returned that key. |
96 Map<Object, List> groupBy(Iterable iter, fn(element)) { | 99 Map<Object, List> groupBy(Iterable iter, fn(element)) { |
97 var map = {}; | 100 var map = {}; |
98 for (var element in iter) { | 101 for (var element in iter) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 subscription = callback().listen(controller.add, | 251 subscription = callback().listen(controller.add, |
249 onError: controller.addError, | 252 onError: controller.addError, |
250 onDone: controller.close); | 253 onDone: controller.close); |
251 }, | 254 }, |
252 onCancel: () => subscription.cancel(), | 255 onCancel: () => subscription.cancel(), |
253 onPause: () => subscription.pause(), | 256 onPause: () => subscription.pause(), |
254 onResume: () => subscription.resume(), | 257 onResume: () => subscription.resume(), |
255 sync: true); | 258 sync: true); |
256 return controller.stream; | 259 return controller.stream; |
257 } | 260 } |
OLD | NEW |