Beta (still building)

groupBy

groupBy operator groups the emits value by provided selection function

Definition:

groupBy(keySelector, elementSelector?)

keySelector: selection function to extract the key for each item.

elementSelector?: function that extracts the return element for each item.

Example: groupBy operator

import { interval } from 'rxjs';
import { groupBy, take } from 'rxjs/operators';

const source$ = interval(1500).pipe(take(10));

const result$ = source$.pipe(groupBy(i => i%3));


Example: groupBy operator with elementSelector

import { of } from 'rxjs';
import { groupBy, concatMap, delay} from 'rxjs/operators';

const items = [
  { name: 'Pizza', category: 'foot' },
  { name: 'Bread', category: 'foot' },
  { name: 'Iphone X', category: 'phone' },
  { name: 'Pixel', category: 'phone' }
];

const source$ = of(...items).pipe(
  concatMap( i => of(i).pipe(delay(1500)))
)

const result$ = source$.pipe(
  groupBy(i => i.category, i => i.name)
);

Official Doc: rxjs.groupBy