single
signature: single(a: Function): Observable
single(a: Function): Observable조건을 만족하는 아이템이 하나밖에 없는지 확인하고, 맞다면 값을 발생시킵니다.
예시
// RxJS v6+
import { from } from 'rxjs';
import { single } from 'rxjs/operators';
// (1,2,3,4,5)를 발생시킵니다
const source = from([1, 2, 3, 4, 5]);
//조건을 만족하는 하나의 아이템을 발생시킵니다
const example = source.pipe(single(val => val === 4));
//결과: 4
const subscribe = example.subscribe(val => console.log(val));추가 자료
Last updated
Was this helpful?