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
I'm not sure this issue is resolved by adding Single.toCompletable()?
My question was how to "link" a Single to a Completable using an operator like flatMap so that the Completable can use the result from the Single. If I transform my source Single to a completable using Single.toCompletable() then the value is lost.
My suggestion is to add Single.flatMapCompletable().
Reacted by Mladen Rakonjac, Yakovlev Victor, Guybrush, Rodolfo Gusson and LWY
so that the Completable can use the result from the Single
Completable is value-less type, you won't be able to use result from Single or Observable. It was created to replace Observable<Void> / Single<Void> when you just need to perform some side-effect work.
CompletablesaveData(Datadata) {
// Creates and returns a Completable that saves some data in local storage
}
Then in class B I have a method that retrieves some data from a REST API
Single<Data> retrieveData() {
// Creates and returns a Single that gets some data
}
Now from class C I want to flatMap both methods so when retrieveData() completes I can pass the result to saveData(data). Are you suggesting that saveData(data) should return a Single instead of a Completable? I would imagine a Completable is a better option because I don't care about the value after it's been saved.
Reacted by Patrick Ruhkopf, Evgeniy Biletskyi, ULazdins, Dariusz Baciński, denissinclair, Eduard Dudar, Dzmitry Lakisau, hamid reza gholami, JP Ventura, Guybrush and 1 more
Yeah, that makes sense. I want the final result to be a Completable so the first option would work for me. However it seems a bit redundant having to call toSingle() and then call toCompletable(). That's why I was thinking that adding a new operator like single.flatMapCompletable() could be useful.
Thanks.
Could this please be re-opened? The scenario with a save method seems like a prime use case for Completable. To say that you can't go from Single to a nested save is pretty hard to accept.
Reacted by Guybrush, Rish Bhardwaj and Rodolfo Gusson
Activity
artem-zinnatullin commentedon Apr 18, 2016
At the moment you can pass the
SingletoCompletable.fromSingle(), I'll submit a PR forSingle.toCompletable().1.x: Add Single.toCompletable() (#3866)
ivacf commentedon Apr 19, 2016
I'm not sure this issue is resolved by adding
Single.toCompletable()?My question was how to "link" a
Singleto aCompletableusing an operator likeflatMapso that theCompletablecan use the result from theSingle. If I transform my sourceSingleto a completable usingSingle.toCompletable()then the value is lost.My suggestion is to add
Single.flatMapCompletable().artem-zinnatullin commentedon Apr 19, 2016
Completableis value-less type, you won't be able to use result fromSingleorObservable. It was created to replaceObservable<Void> / Single<Void>when you just need to perform some side-effect work.Can you use
Singleinstead ofCompletable?ivacf commentedon Apr 19, 2016
So If I have a method in class
Alike this:Then in class
BI have a method that retrieves some data from a REST APINow from class
CI want toflatMapboth methods so whenretrieveData()completes I can pass the result tosaveData(data). Are you suggesting thatsaveData(data)should return aSingleinstead of aCompletable? I would imagine aCompletableis a better option because I don't care about the value after it's been saved.artem-zinnatullin commentedon Apr 19, 2016
If you want final result to be
Completablethen one way is to do:If you want final result to be
Singlethen one way to do this:ivacf commentedon Apr 19, 2016
Yeah, that makes sense. I want the final result to be a
Completableso the first option would work for me. However it seems a bit redundant having to calltoSingle()and then calltoCompletable(). That's why I was thinking that adding a new operator likesingle.flatMapCompletable()could be useful.Thanks.
nhaarman commentedon May 31, 2016
A simple extension function in Kotlin would be the following:
rstoyanchev commentedon Jul 27, 2016
Could this please be re-opened? The scenario with a save method seems like a prime use case for
Completable. To say that you can't go from Single to a nested save is pretty hard to accept.akarnokd commentedon Jul 27, 2016
There is the PR #4226 for that.
rstoyanchev commentedon Jul 27, 2016
Didn't see that thanks!