If you don't need a result then you can ignoreElement()
to convert your flow into Completable
and use toSingleDefault(...)
function:
uploadData(apiResponse.getUrl())
.ignoreElement()
.toSingleDefault(new FinalResult());
In case you just need to convert the response into FinalResult
then you can use map(...)
:
uploadData(apiResponse.getUrl())
.map(uploadResponse -> new FinalResult(uploadResponse));
In case you have to utilize the result from uploadData(..)
with any external calls or whatever then flatMap()
is your choice:
uploadData(apiResponse.getUrl())
.flatMap(uploadResponse -> {
// do whatever you want with response
return Single.just(new FinalResult(uploadResponse));
});
UPDATE:
In your case it can be simplified:
return processData(fileData)
.flatMap(processedData -> {
Single<FinalResult> postProcessing;
if (processedData.length > LIMIT) {
postProcessing = uploadData(apiResponse.getUrl())
.map(response -> new FinalResult(response));
} else {
postProcessing = Single.just(new FinalResult());
}
return callAPI(id, processedData)
.ignoreElement()
.andThen(postProcessing);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…