ReactiveX/RxJava — pull request #1727 by benjchristensen (2014-10-06 05:39:42+00:00)
Title: Proposed groupBy/groupByUntil Changes

This is a proposed change to `groupBy` and `groupByUntil` that does the following:

1) Eliminate `groupByUntil` and rolls that functionality into `groupBy`
2) Adds support for reactive pull backpressure to `groupBy`
3) Child `GroupedObservable`s can now be unsubscribed and they will be cleaned up and then new instances for the same key can be emitted, like `groupByUntil` worked, except that now instead of passing in a special durationSelector function, the child can be composed using `take`/`takeUntil`/etc to cause an unsubscribe.

If the previous non-obvious groupBy behavior is wanted, then instead of unsubscribing, it can be filtered to ignore all further data, which is what the old groupBy used to do when a child was unsubscribed.

The reason for these changes are:

- Adding backpressure to `groupByUntil` was very difficult with its existing signature as the duration selector function effectively required a `GroupedObservable` being a `PublishSubject` which meant multicasting. In this specific case it may have been possible to do backpressure with the multicasting, but it would be difficult and non-obvioius as generally multicasting means the stream is "hot" and reactive pull backpressure can't be applied.
- The existing `groupBy` almost always confused people as to what would happen when they unsubscribed a child using `take` or `takeUntil`. It always surprised people that it meant all further data would be dropped but the key and group would not be garbage collected. Almost always on an infinite stream people determined they needed `groupByUntil`, but only after stumbling around. After speaking with @headinthebox about this briefly we had enough agreement to submit this proposal and discuss further.

Now `groupBy` can behave by default as people expect with `unsubscribe` and support infinite streams, garbage collection, etc as well as backpressure.

I will provide usage examples below.