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 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 } | 134 } |
135 helper(nested); | 135 helper(nested); |
136 return result; | 136 return result; |
137 } | 137 } |
138 | 138 |
139 /// Returns the union of all elements in each set in [sets]. | 139 /// Returns the union of all elements in each set in [sets]. |
140 Set unionAll(Iterable<Set> sets) => | 140 Set unionAll(Iterable<Set> sets) => |
141 sets.fold(new Set(), (union, set) => union.union(set)); | 141 sets.fold(new Set(), (union, set) => union.union(set)); |
142 | 142 |
143 /// Passes each key/value pair in [map] to [fn] and returns a new [Map] whose | 143 /// Creates a new map from [map] with new keys and values. |
144 /// values are the return values of [fn]. | 144 /// |
145 Map mapMapValues(Map map, fn(key, value)) => | 145 /// The return values of [keyFn] are used as the keys and the return values of |
146 new Map.fromIterable(map.keys, value: (key) => fn(key, map[key])); | 146 /// [valueFn] are used as the values for the new map. |
| 147 Map mapMap(Map map, keyFn(key, value), valueFn(key, value)) => |
| 148 new Map.fromIterable(map.keys, |
| 149 key: (key) => keyFn(key, map[key]), |
| 150 value: (key) => valueFn(key, map[key])); |
| 151 |
| 152 /// Creates a new map from [map] with the same keys. |
| 153 /// |
| 154 /// The return values of [fn] are used as the values for the new map. |
| 155 Map mapMapValues(Map map, fn(key, value)) => mapMap(map, (key, _) => key, fn); |
| 156 |
| 157 /// Creates a new map from [map] with the same keys. |
| 158 /// |
| 159 /// The return values of [fn] are used as the keys for the new map. |
| 160 Map mapMapKeys(Map map, fn(key, value)) => mapMap(map, fn, (_, value) => value); |
147 | 161 |
148 /// Returns whether [set1] has exactly the same elements as [set2]. | 162 /// Returns whether [set1] has exactly the same elements as [set2]. |
149 bool setEquals(Set set1, Set set2) => | 163 bool setEquals(Set set1, Set set2) => |
150 set1.length == set2.length && set1.containsAll(set2); | 164 set1.length == set2.length && set1.containsAll(set2); |
151 | 165 |
152 /// Merges [streams] into a single stream that emits events from all sources. | 166 /// Merges [streams] into a single stream that emits events from all sources. |
153 /// | 167 /// |
154 /// If [broadcast] is true, this will return a broadcast stream; otherwise, it | 168 /// If [broadcast] is true, this will return a broadcast stream; otherwise, it |
155 /// will return a buffered stream. | 169 /// will return a buffered stream. |
156 Stream mergeStreams(Iterable<Stream> streams, {bool broadcast: false}) { | 170 Stream mergeStreams(Iterable<Stream> streams, {bool broadcast: false}) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 subscription = callback().listen(controller.add, | 282 subscription = callback().listen(controller.add, |
269 onError: controller.addError, | 283 onError: controller.addError, |
270 onDone: controller.close); | 284 onDone: controller.close); |
271 }, | 285 }, |
272 onCancel: () => subscription.cancel(), | 286 onCancel: () => subscription.cancel(), |
273 onPause: () => subscription.pause(), | 287 onPause: () => subscription.pause(), |
274 onResume: () => subscription.resume(), | 288 onResume: () => subscription.resume(), |
275 sync: true); | 289 sync: true); |
276 return controller.stream; | 290 return controller.stream; |
277 } | 291 } |
OLD | NEW |