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

2.x: Convert Observable to Single without a default value #4588

Closed
vanniktech opened this issue Sep 23, 2016 · 11 comments
Closed

2.x: Convert Observable to Single without a default value #4588

vanniktech opened this issue Sep 23, 2016 · 11 comments
Labels

Comments

@vanniktech
Copy link
Collaborator

With the RC3 changes I don't see an easy way of converting an Observable into a Single without giving a default value.

How do you feel about adding methods for that?

@akarnokd
Copy link
Member

akarnokd commented Sep 23, 2016

@abersnaze didn't like throwing because being empty. Try your API through Maybe and switchIfEmpty(Maybe.error()).

Edit wrong method name, fixed.

@vanniktech
Copy link
Collaborator Author

defaultIfEmpty(MaybeSource<T>) does not exist

@akarnokd
Copy link
Member

Yeah sorry, switchIfEmpty() (I sometimes mix the two as defaultIfEmpty delegates to switchIfEmpty).

@vanniktech
Copy link
Collaborator Author

I don't quite see how switchIfEmpty solves my original problem. Maybe.switchIfEmpty() still returns a Maybe.

Also I'd rather have a NoSuchElementException and fail early than passing in a default value when converting an Observable to Single.

@akarnokd
Copy link
Member

You could restore toSingle (under singleOrError), only the surface API has been removed.

@vanniktech
Copy link
Collaborator Author

So basically add to Observable + Flowable:

singleOrError
firstOrError
lastOrError
elementAtOrError

@akarnokd
Copy link
Member

Yes.

@vanniktech
Copy link
Collaborator Author

Alright cool will do

@abersnaze
Copy link
Contributor

Does singleElement() error on more than one but not on empty?

@akarnokd
Copy link
Member

Yes, that was kept and also why firstElement is there to ignore more without signalling.

@JakeWharton
Copy link
Contributor

This can be closed right?

@akarnokd akarnokd closed this as completed Oct 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants