Demo:  groupBy

groupBy operator emits a new observable for each new group value, calculated by the grouping criteria.

And, it emits the data, belonging to the same group, in its respective observable.

//Criteria (v%4) creates observable groups- 0,1,2 & 3
const input = timer(0,1200).pipe(
                      take(10),
                      groupBy(v => v%4) );

//Let each grouping observable,
//    collect it's values in a separate array using scan
//And emit the array as we collect a new item
const process = mergeMap(v =>
              v.pipe(scan((acc,v) => [...acc,v], [])));

const output=input.pipe(process).subscribe(v=>console.log(v))