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 return new Uint8List.view((input as TypedData).buffer); | |
Bob Nystrom
2013/11/16 00:59:16
I thought the analyzer was supposed to allow this
nweiz
2013/11/16 01:12:50
Done.
| |
90 } | |
89 return new Uint8List.fromList(input); | 91 return new Uint8List.fromList(input); |
90 } | 92 } |
91 | 93 |
92 /// Group the elements in [iter] by the value returned by [fn]. | 94 /// Group the elements in [iter] by the value returned by [fn]. |
93 /// | 95 /// |
94 /// This returns a map whose keys are the return values of [fn] and whose values | 96 /// 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. | 97 /// are lists of each element in [iter] for which [fn] returned that key. |
96 Map<Object, List> groupBy(Iterable iter, fn(element)) { | 98 Map<Object, List> groupBy(Iterable iter, fn(element)) { |
97 var map = {}; | 99 var map = {}; |
98 for (var element in iter) { | 100 for (var element in iter) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 subscription = callback().listen(controller.add, | 250 subscription = callback().listen(controller.add, |
249 onError: controller.addError, | 251 onError: controller.addError, |
250 onDone: controller.close); | 252 onDone: controller.close); |
251 }, | 253 }, |
252 onCancel: () => subscription.cancel(), | 254 onCancel: () => subscription.cancel(), |
253 onPause: () => subscription.pause(), | 255 onPause: () => subscription.pause(), |
254 onResume: () => subscription.resume(), | 256 onResume: () => subscription.resume(), |
255 sync: true); | 257 sync: true); |
256 return controller.stream; | 258 return controller.stream; |
257 } | 259 } |
OLD | NEW |