You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like first, but emit with error notification if there is more than one value.
The above statement is reasonable but it is not the case in the implementation.
Current Behavior
When using single(()=>false) on an empty sequence there is an error correctly thrown notifying about no elements in sequence. But when using single(()=>false) on a single-element or multiple-element sequence there is one undefined value emitted (unlike first(()=>false) behaviour ).
Reproduction
from([]).pipe(single(()=>false)).pipe(tap((v)=>console.log(v))).subscribe();
//Error [EmptyError]: no elements in sequence]
from(['x']).pipe(single(()=>false)).pipe(tap((v)=>console.log(v))).subscribe();
//undefined
from([]).pipe(first(()=>false)).pipe(tap((v)=>console.log(v))).subscribe();
//[Error [EmptyError]: no elements in sequence]
from(['x']).pipe(first(()=>false)).pipe(tap((v)=>console.log(v))).subscribe();
//[Error [EmptyError]: no elements in sequence]
Expected behavior
In my opinion, the same or some other error should be thrown on the latter case of single also, instead of an undefined value, as it happens with the case of first(()=>false).
Environment
Runtime: [e.g. Node v12.13.1]
RxJS version: 6.5.4
Possible Solution
Additional context/Screenshots
The text was updated successfully, but these errors were encountered:
ghuser
changed the title
single(()=>false) should have the same behavior on empty and non-empty sequences as first(()=>false) does.
single(()=>false) should have the same behavior on empty and non-empty sequences as first(()=>false) does.
Feb 18, 2020
It seems like we're missing an error type for something like "Element Not Found" or whatever. It's not really that the sequence was empty so much as it was nothing matched.
Bug Report
In the documentation of single I read:
The above statement is reasonable but it is not the case in the implementation.
Current Behavior
When using
single(()=>false)
on an empty sequence there is an error correctly thrown notifying aboutno elements in sequence
. But when usingsingle(()=>false)
on a single-element or multiple-element sequence there is oneundefined
value emitted (unlikefirst(()=>false)
behaviour ).Reproduction
Expected behavior
In my opinion, the same or some other error should be thrown on the latter case of
single
also, instead of anundefined
value, as it happens with the case offirst(()=>false)
.Environment
6.5.4
Possible Solution
Additional context/Screenshots
The text was updated successfully, but these errors were encountered: