Learn RxJS
Search…
single

signature: single(a: Function): Observable

Emit single item that passes expression.

Examples

Example 1: Emit first number passing predicate
1
// RxJS v6+
2
import { from } from 'rxjs';
3
import { single } from 'rxjs/operators';
4
5
//emit (1,2,3,4,5)
6
const source = from([1, 2, 3, 4, 5]);
7
//emit one item that matches predicate
8
const example = source.pipe(single(val => val === 4));
9
//output: 4
10
const subscribe = example.subscribe(val => console.log(val));
Copied!

Additional Resources

    single 📰 - Official docs
Last modified 1yr ago