single
signature: single(a: Function): Observable
Emit single item that passes expression.
Examples
Example 1: Emit first number passing predicate
( jsBin |
jsFiddle )
import { from } from 'rxjs/observable/from';
import { single } 'rxjs/operators';
const source = from([1, 2, 3, 4, 5]);
const example = source.pipe(single(val => val === 4));
const subscribe = example.subscribe(val => console.log(val));
Additional Resources
Source Code:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/single.ts