Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Unified Diff: packages/barback/lib/src/utils.dart

Issue 3015713002: Roll to pickup pool changes
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: packages/barback/lib/src/utils.dart
diff --git a/packages/barback/lib/src/utils.dart b/packages/barback/lib/src/utils.dart
index e991078bcc4b08010244fbdef1ab84caac4c4c2a..71dd2292229a12fba3d376410072b1bf545706f4 100644
--- a/packages/barback/lib/src/utils.dart
+++ b/packages/barback/lib/src/utils.dart
@@ -130,9 +130,8 @@ Uint8List toUint8List(List<int> input) {
///
/// This returns a map whose keys are the return values of [fn] and whose values
/// are lists of each element in [iter] for which [fn] returned that key.
-Map<Object/*=T*/, List/*<S>*/> groupBy/*<S, T>*/(Iterable/*<S>*/ iter,
- /*=T*/ fn(/*=S*/ element)) {
- var map = /*<T, List<S>>*/{};
+Map<Object, List<S>> groupBy<S, T>(Iterable<S> iter, T fn(S element)) {
+ var map = <T, List<S>>{};
for (var element in iter) {
var list = map.putIfAbsent(fn(element), () => []);
list.add(element);
@@ -153,50 +152,48 @@ List flatten(Iterable nested) {
}
}
}
+
helper(nested);
return result;
}
/// Returns the union of all elements in each set in [sets].
-Set/*<T>*/ unionAll/*<T>*/(Iterable<Set/*<T>*/> sets) =>
- sets.fold(new Set(), (union, set) => union.union(set));
+Set<T> unionAll<T>(Iterable<Set<T>> sets) =>
+ sets.fold(new Set(), (union, set) => union.union(set));
/// Creates a new map from [map] with new keys and values.
///
/// The return values of [keyFn] are used as the keys and the return values of
/// [valueFn] are used as the values for the new map.
-Map/*<K2, V2>*/ mapMap/*<K1, V1, K2, V2>*/(Map/*<K1, V1>*/ map,
- /*=K2*/ keyFn(/*=K1*/ key, /*=V1*/ value),
- /*=V2*/ valueFn(/*=K1*/ key, /*=V1*/ value)) =>
- new Map.fromIterable(map.keys,
- key: (key) => keyFn(key as dynamic/*=K1*/, map[key]),
- value: (key) => valueFn(key as dynamic/*=K1*/, map[key]));
+Map<K2, V2> mapMap<K1, V1, K2, V2>(Map<K1, V1> map, K2 keyFn(K1 key, V1 value),
+ V2 valueFn(K1 key, V1 value)) =>
+ new Map.fromIterable(map.keys,
+ key: (key) => keyFn(key as K1, map[key]),
+ value: (key) => valueFn(key as K1, map[key]));
/// Creates a new map from [map] with the same keys.
///
/// The return values of [fn] are used as the values for the new map.
-Map/*<K, V2>*/ mapMapValues/*<K, V1, V2>*/(Map/*<K, V1>*/ map,
- /*=V2*/ fn(/*=K*/ key, /*=V1*/ value)) =>
- // TODO(nweiz): Don't explicitly type [key] when sdk#25490 is fixed.
- mapMap(map, (/*=K*/ key, _) => key, fn);
+Map<K, V2> mapMapValues<K, V1, V2>(Map<K, V1> map, V2 fn(K key, V1 value)) =>
+ // TODO(nweiz): Don't explicitly type [key] when sdk#25490 is fixed.
+ mapMap(map, (K key, _) => key, fn);
/// Creates a new map from [map] with the same keys.
///
/// The return values of [fn] are used as the keys for the new map.
-Map/*<K2, V>*/ mapMapKeys/*<K1, V, K2>*/(Map/*<K1, V>*/ map,
- /*=K2*/ fn(/*=K1*/ key, /*=V*/ value)) =>
- // TODO(nweiz): Don't explicitly type [value] when sdk#25490 is fixed.
- mapMap(map, fn, (_, /*=V*/ value) => value);
+Map<K2, V> mapMapKeys<K1, V, K2>(Map<K1, V> map, K2 fn(K1 key, V value)) =>
+ // TODO(nweiz): Don't explicitly type [value] when sdk#25490 is fixed.
+ mapMap(map, fn, (_, V value) => value);
/// Returns whether [set1] has exactly the same elements as [set2].
bool setEquals(Set set1, Set set2) =>
- set1.length == set2.length && set1.containsAll(set2);
+ set1.length == set2.length && set1.containsAll(set2);
/// Merges [streams] into a single stream that emits events from all sources.
///
/// If [broadcast] is true, this will return a broadcast stream; otherwise, it
/// will return a buffered stream.
-Stream/*<T>*/ mergeStreams/*<T>*/(Iterable<Stream/*<T>*/> streams,
+Stream<T> mergeStreams<T>(Iterable<Stream<T>> streams,
{bool broadcast: false}) {
streams = streams.toList();
var doneCount = 0;
@@ -205,14 +202,11 @@ Stream/*<T>*/ mergeStreams/*<T>*/(Iterable<Stream/*<T>*/> streams,
// async, then the events we receive will also be async, and forwarding them
// sync won't change that.
var controller = broadcast
- ? new StreamController/*<T>*/.broadcast(sync: true)
- : new StreamController/*<T>*/(sync: true);
+ ? new StreamController<T>.broadcast(sync: true)
+ : new StreamController<T>(sync: true);
for (var stream in streams) {
- stream.listen(
- controller.add,
- onError: controller.addError,
- onDone: () {
+ stream.listen(controller.add, onError: controller.addError, onDone: () {
doneCount++;
if (doneCount == streams.length) controller.close();
});
@@ -238,7 +232,7 @@ String prefixLines(String text, {String prefix: '| ', String firstPrefix}) {
/// Returns a [Future] that completes after pumping the event queue [times]
/// times. By default, this should pump the event queue enough times to allow
/// any code to run, as long as it's not waiting on some external event.
-Future pumpEventQueue([int times=20]) {
+Future pumpEventQueue([int times = 20]) {
if (times == 0) return new Future.value();
// We use a delayed future to allow microtask events to finish. The
// Future.value or Future() constructors use scheduleMicrotask themselves and
@@ -249,7 +243,7 @@ Future pumpEventQueue([int times=20]) {
/// Like [new Future], but avoids dartbug.com/11911 by using async/await under
/// the covers.
-Future/*<T>*/ newFuture/*<T>*/(/*=T*/ callback()) async => await callback();
+Future<T> newFuture<T>(T callback()) async => await callback();
/// Returns a buffered stream that will emit the same values as the stream
/// returned by [future] once [future] completes.
@@ -260,10 +254,9 @@ Future/*<T>*/ newFuture/*<T>*/(/*=T*/ callback()) async => await callback();
/// If [broadcast] is true, a broadcast stream is returned. This assumes that
/// the stream returned by [future] will be a broadcast stream as well.
/// [broadcast] defaults to false.
-Stream/*<T>*/ futureStream/*<T>*/(Future<Stream/*<T>*/> future,
- {bool broadcast: false}) {
- StreamSubscription/*<T>*/ subscription;
- StreamController/*<T>*/ controller;
+Stream<T> futureStream<T>(Future<Stream<T>> future, {bool broadcast: false}) {
+ StreamSubscription<T> subscription;
+ StreamController<T> controller;
future = DelegatingFuture.typed(future.catchError((e, stackTrace) {
// Since [controller] is synchronous, it's likely that emitting an error
@@ -276,10 +269,8 @@ Stream/*<T>*/ futureStream/*<T>*/(Future<Stream/*<T>*/> future,
onListen() {
future.then((stream) {
if (controller == null) return;
- subscription = stream.listen(
- controller.add,
- onError: controller.addError,
- onDone: controller.close);
+ subscription = stream.listen(controller.add,
+ onError: controller.addError, onDone: controller.close);
});
}
@@ -290,10 +281,10 @@ Stream/*<T>*/ futureStream/*<T>*/(Future<Stream/*<T>*/> future,
}
if (broadcast) {
- controller = new StreamController/*<T>*/.broadcast(
+ controller = new StreamController<T>.broadcast(
sync: true, onListen: onListen, onCancel: onCancel);
} else {
- controller = new StreamController/*<T>*/(
+ controller = new StreamController<T>(
sync: true, onListen: onListen, onCancel: onCancel);
}
return controller.stream;
@@ -303,14 +294,14 @@ Stream/*<T>*/ futureStream/*<T>*/(Future<Stream/*<T>*/> future,
/// [callback].
///
/// [callback] will only be called when the returned [Stream] gets a subscriber.
-Stream/*<T>*/ callbackStream/*<T>*/(Stream/*<T>*/ callback()) {
- StreamSubscription/*<T>*/ subscription;
- StreamController/*<T>*/ controller;
- controller = new StreamController/*<T>*/(onListen: () {
- subscription = callback().listen(controller.add,
- onError: controller.addError,
- onDone: controller.close);
- },
+Stream<T> callbackStream<T>(Stream<T> callback()) {
+ StreamSubscription<T> subscription;
+ StreamController<T> controller;
+ controller = new StreamController<T>(
+ onListen: () {
+ subscription = callback().listen(controller.add,
+ onError: controller.addError, onDone: controller.close);
+ },
onCancel: () => subscription.cancel(),
onPause: () => subscription.pause(),
onResume: () => subscription.resume(),
@@ -322,17 +313,16 @@ Stream/*<T>*/ callbackStream/*<T>*/(Stream/*<T>*/ callback()) {
///
/// The returned stream will enqueue events from [broadcast] until a listener is
/// attached, then pipe events to that listener.
-Stream/*<T>*/ broadcastToSingleSubscription/*<T>*/(Stream/*<T>*/ broadcast) {
+Stream<T> broadcastToSingleSubscription<T>(Stream<T> broadcast) {
if (!broadcast.isBroadcast) return broadcast;
// TODO(nweiz): Implement this using a transformer when issues 18588 and 18586
// are fixed.
var subscription;
- var controller = new StreamController/*<T>*/(
- onCancel: () => subscription.cancel());
+ var controller =
+ new StreamController<T>(onCancel: () => subscription.cancel());
subscription = broadcast.listen(controller.add,
- onError: controller.addError,
- onDone: controller.close);
+ onError: controller.addError, onDone: controller.close);
return controller.stream;
}
@@ -345,7 +335,7 @@ final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
/// Many exceptions include the exception class name at the beginning of their
/// [toString], so we remove that if it exists.
String getErrorMessage(error) =>
- error.toString().replaceFirst(_exceptionPrefix, '');
+ error.toString().replaceFirst(_exceptionPrefix, '');
/// Returns a human-friendly representation of [duration].
String niceDuration(Duration duration) {

Powered by Google App Engine
This is Rietveld 408576698