ReactiveX / reactivex.github.io

ReactiveX Website
Apache License 2.0
139 stars 138 forks source link

Rxjs documentation for 'find' operator is wrong #319

Open cmaart opened 7 years ago

cmaart commented 7 years ago

The documentation at http://reactivex.io/documentation/operators/first.html is slightly wrong for the find operator, in rxjs at least. Documentation says that find emits undefined when no element matches. This is not correct, actually it just completes the observable. The sample given:

var array = [1,2,3,4];

var source = Rx.Observable.fromArray(array)
    .find(function (x, i, obs) {
        return x === 5;
    });

var subscription = source.subscribe(
    function (x) { console.log('Next: ' + x); },
    function (err) { console.log('Error: ' + err); },
    function () { console.log('Completed'); });

outputs accordin to the documentation:

Next: undefined
Completed

but actually outputs: Completed

Also see rxjs documentation for find: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/find.md

akarnokd commented 1 month ago

According to the most recent official docs, it is supposed to emit undefined:

https://rxjs.dev/api/index/function/find