Skip to content

Commit

Permalink
Rename StreamGroup to GroupedEvents.
Browse files Browse the repository at this point in the history
Avoids clash with StreamGroup from package:async.

R=floitsch@google.com

Review-Url: https://codereview.chromium.org/2872263003 .
  • Loading branch information
lrhn committed May 11, 2017
1 parent efe0e76 commit 3f90b06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions sdk/lib/async/stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ abstract class Stream<T> {
///
/// A key is extracted from incoming events.
/// The first time a key is seen, a stream is created for it, and emitted
/// on the returned stream, along with the key, as a [StreamGroup] object.
/// Then the event is emitted on the stream ([StreamGroup.values])
/// on the returned stream, along with the key, as a [GroupedEvents] object.
/// Then the event is emitted on the stream ([GroupedEvents.values])
/// corresponding to the key.
///
/// An error on the source stream, or when calling the `key` functions,
Expand All @@ -406,11 +406,11 @@ abstract class Stream<T> {
/// Pausing or canceling an individual group stream has no effect other than
/// on that stream. Events will be queued while the group stream
/// is paused and until it is first listened to.
/// If the [StreamGroup.values] stream is never listened to,
/// If the [GroupedEvents.values] stream is never listened to,
/// it will enqueue all the events unnecessarily.
Stream<StreamGroup<K, T>> groupBy<K>(K key(T event)) {
Stream<GroupedEvents<K, T>> groupBy<K>(K key(T event)) {
var controller;
controller = new StreamController<StreamGroup<K, T>>(
controller = new StreamController<GroupedEvents<K, T>>(
sync: true,
onListen: () {
var groupControllers = new HashMap<K, StreamController<T>>();
Expand All @@ -436,7 +436,7 @@ abstract class Stream<T> {
new StreamController<T>.broadcast(sync: true);
groupControllers[theKey] = groupController;
controller.add(
new StreamGroup<K, T>(theKey, groupController.stream));
new GroupedEvents<K, T>(theKey, groupController.stream));
}
groupController.add(data);
},
Expand Down Expand Up @@ -1909,23 +1909,23 @@ class _ControllerEventSinkWrapper<T> implements EventSink<T> {

/// A group created by [Stream.groupBy] or [Stream.groupByMapped].
///
/// The stream created by `groupBy` emits a `StreamGroup` for each distinct key
/// The stream created by `groupBy` emits a `GroupedEvents` for each distinct key
/// it encounters.
/// This group contains the [key] itself, along with a stream of the [values]
/// associated with that key.
class StreamGroup<K, V> {
class GroupedEvents<K, V> {
/// The key that identifiers the values emitted by [values].
final K key;

/// The [values] that [GroupBy] have grouped by the common [key].
final Stream<V> values;

factory StreamGroup(K key, Stream<V> values) = StreamGroup<K, V>._;
factory GroupedEvents(K key, Stream<V> values) = GroupedEvents<K, V>._;

// Don't expose a generative constructor.
// This class is not intended for subclassing, so we don't want to promise
// it. We can change that in the future.
StreamGroup._(this.key, this.values);
GroupedEvents._(this.key, this.values);

/// Tells [values] to discard values instead of retaining them.
///
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/async/stream_group_by_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
test("splits", () async {
var grouped = stringStream.groupBy<int>(len);
var byLength = <int, Future<List<String>>>{};
await for (StreamGroup<int, String> group in grouped) {
await for (GroupedEvents<int, String> group in grouped) {
byLength[group.key] = group.values.toList();
}
Expect.listEquals([1, 2, 4, 3], byLength.keys.toList());
Expand All @@ -31,7 +31,7 @@ void main() {
test("empty", () async {
var grouped = emptyStream.groupBy<int>(len);
var byLength = <int, Future<List<String>>>{};
await for (StreamGroup<int, String> group in grouped) {
await for (GroupedEvents<int, String> group in grouped) {
byLength[group.key] = group.values.toList();
}
Expect.isTrue(byLength.isEmpty);
Expand All @@ -40,7 +40,7 @@ void main() {
test("single group", () async {
var grouped = repeatStream(5, "x").groupBy<int>(len);
var byLength = <int, Future<List<String>>>{};
await for (StreamGroup<int, String> group in grouped) {
await for (GroupedEvents<int, String> group in grouped) {
byLength[group.key] = group.values.toList();
}
Expect.listEquals([1], byLength.keys.toList());
Expand All @@ -52,7 +52,7 @@ void main() {
var byLength = <int, Future<List<String>>>{};
bool caught = false;
try {
await for (StreamGroup<int, String> group in grouped) {
await for (GroupedEvents<int, String> group in grouped) {
byLength[group.key] = group.values.toList();
}
} catch (e) {
Expand Down

0 comments on commit 3f90b06

Please sign in to comment.