skip to content

first

 

first operator re-emits the first emission from the source and then completes

Also check out this first vs take vs single head-to-head comparison

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const { rxObserver } = require('api/v0.3');
const { timer } = require('rxjs');
const { take, first } = require('rxjs/operators');

const source$ = timer(10, 10).pipe(
    take(10)
  );

const result$ = source$.pipe(
    first()
  );


source$.subscribe(rxObserver('source'));
result$.subscribe(rxObserver('first()'));

0mssourcestartcomplete00 11 22 33 44 55 66 77 88 99 first()startcomplete00