Learn RxJS
Search
K
Comment on page

single

signature: single(a: Function): Observable

Emit single item that passes expression.

Ultimate RxJS

Examples

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

Additional Resources

  • single 📰 - Official docs
Last modified 3yr ago