Logically, you cannot know how many members will be in an Observable group until the source stream completes - since any element could potentially contribute to any of the groups.
Ergo, you cannot filter the groups by their count until the source stream is finished, and you must consent to cache the results and then process them.
In other words, IEnumerable<T>
is the way to go here. Sure, you could turn it back into an IObservable<T>
, but there's probably no point.
As an aside, if you do ever need to filter groups, do it in a Select
clause as in this simple example. It won't work for Count()
though, for the reasons mentioned above:
var source = Observable.Range(0, 10);
source.GroupBy(n => n < 5)
.Select(x => x.Where(y => y % 2 == 0));