Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

single(()=>false) should have the same behavior on empty and non-empty sequences as first(()=>false) does. #5320

Closed
ghuser opened this issue Feb 18, 2020 · 3 comments
Assignees
Labels
bug Confirmed bug

Comments

@ghuser
Copy link

ghuser commented Feb 18, 2020

Bug Report

In the documentation of single I read:

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

@cartant cartant added the bug Confirmed bug label Feb 18, 2020
@ghuser 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
@benlesh
Copy link
Member

benlesh commented Feb 22, 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.

@benlesh benlesh added the AGENDA ITEM Flagged for discussion at core team meetings label Feb 22, 2020
@benlesh
Copy link
Member

benlesh commented Feb 26, 2020

It looks like single is wrong in a lot of cases.

If it finds two matches, it just completes and does not error, which is incorrect. It should throw. This needs fixed for v7.

@benlesh benlesh removed the AGENDA ITEM Flagged for discussion at core team meetings label Feb 26, 2020
@benlesh benlesh self-assigned this Feb 26, 2020
@cartant
Copy link
Collaborator

cartant commented Mar 15, 2021

Closed by #5325 AFAICT.

@cartant cartant closed this as completed Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants