Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

Single operator emits undefined (instead of NoSuchElementException) when no items match the predicate #1471

Open ChrisMondok opened 7 years ago

ChrisMondok commented 7 years ago

Given an observable that emits at least one value, Observable.single emits a single "undefined" value, rather than a NoSuchElementException. This is unexpected, and contradicts the documentation.

Code sample:

Rx.Observable.from([1,2,3])
  .single(n => n > 10)
  .subscribe(
      n => console.log(`number is ${n}`),
      e => console.error(`error is ${e}`));

Result:

number is undefined

Expected result:

error is NoSuchElementException: no elements in sequence