Eugene V.
Eugene V.

Reputation: 100

Maybe after Completable in chain

How can I create a chain right way in next case? Now I have:

someSingle()
.filter{...}
.flatMapSingleElement { Single.create {...} }
.doOnError(...)
.onErrorReturnItem(...)
.switchIfEmpty(...)

But I need to paste anotherSingle() and someCompletable() after someSingle() in chain and don't break this chain. So I try the next:

someSingle()
.filter{...}
.flatMapSingle { anotherSingle() }
.flatMapCompletable { someCompletable() }

and what I can do next to continue the chain with

.flatMapSingleElement { Single.create {...} }
.doOnError(...)
.onErrorReturnItem(...)
.switchIfEmpty(...)

?

Upvotes: 1

Views: 1008

Answers (1)

Thracian
Thracian

Reputation: 66759

You can use andThen operator.

 someSingle()
.filter{...}
.flatMapSingle { anotherSingle() }
.flatMapCompletable { someCompletable() }
.andThen(Maybe.just())

or as an example

  Single.just("Hello")
        .flatMapCompletable {
            Completable.complete()
        }
        .andThen(Maybe.just("Maybe"))
        .subscribe {
            println("Result $it")
        }

Upvotes: 2

Related Questions