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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 /// Returns the union of all elements in each set in [sets]. | 66 /// Returns the union of all elements in each set in [sets]. |
67 Set unionAll(Iterable<Set> sets) => | 67 Set unionAll(Iterable<Set> sets) => |
68 sets.fold(new Set(), (union, set) => union.union(set)); | 68 sets.fold(new Set(), (union, set) => union.union(set)); |
69 | 69 |
70 /// Passes each key/value pair in [map] to [fn] and returns a new [Map] whose | 70 /// Passes each key/value pair in [map] to [fn] and returns a new [Map] whose |
71 /// values are the return values of [fn]. | 71 /// values are the return values of [fn]. |
72 Map mapMapValues(Map map, fn(key, value)) => | 72 Map mapMapValues(Map map, fn(key, value)) => |
73 new Map.fromIterable(map.keys, value: (key) => fn(key, map[key])); | 73 new Map.fromIterable(map.keys, value: (key) => fn(key, map[key])); |
74 | 74 |
| 75 /// Returns whether [set1] has exactly the same elements as [set2]. |
| 76 bool setEquals(Set set1, Set set2) => |
| 77 set1.length == set2.length && set1.containsAll(set2); |
| 78 |
75 /// Merges [streams] into a single stream that emits events from all sources. | 79 /// Merges [streams] into a single stream that emits events from all sources. |
76 Stream mergeStreams(Iterable<Stream> streams) { | 80 Stream mergeStreams(Iterable<Stream> streams) { |
77 streams = streams.toList(); | 81 streams = streams.toList(); |
78 var doneCount = 0; | 82 var doneCount = 0; |
79 // Use a sync stream to preserve the synchrony behavior of the input streams. | 83 // Use a sync stream to preserve the synchrony behavior of the input streams. |
80 // If the inputs are sync, then this will be sync as well; if the inputs are | 84 // If the inputs are sync, then this will be sync as well; if the inputs are |
81 // async, then the events we receive will also be async, and forwarding them | 85 // async, then the events we receive will also be async, and forwarding them |
82 // sync won't change that. | 86 // sync won't change that. |
83 var controller = new StreamController(sync: true); | 87 var controller = new StreamController(sync: true); |
84 | 88 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // We use a delayed future to allow runAsync events to finish. The | 122 // We use a delayed future to allow runAsync events to finish. The |
119 // Future.value or Future() constructors use runAsync themselves and would | 123 // Future.value or Future() constructors use runAsync themselves and would |
120 // therefore not wait for runAsync callbacks that are scheduled after invoking | 124 // therefore not wait for runAsync callbacks that are scheduled after invoking |
121 // this method. | 125 // this method. |
122 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 126 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
123 } | 127 } |
124 | 128 |
125 /// Like [new Future], but avoids issue 11911 by using [new Future.value] under | 129 /// Like [new Future], but avoids issue 11911 by using [new Future.value] under |
126 /// the covers. | 130 /// the covers. |
127 Future newFuture(callback()) => new Future.value().then((_) => callback()); | 131 Future newFuture(callback()) => new Future.value().then((_) => callback()); |
OLD | NEW |