--

So glad you've written this article. I encountered similar issue, except the compiler just don't let it pass.

In my case I was trying to make a custom `Single` after `Completable`. So I wrote

```

val someData = 3L

Completable.complete()

.andThen<Long> {

val someJudge: Boolean = someData > 0L

return@andThen if (someJudge) Single.error<Long>(Exception())

else Single.just<Long>(someData)

}.subscribe {

println("The number is $it")

}

```

but compiler says `andThen` has "Overload resolution ambiguity."

It was that moment, I realized that I could NOT pass `Single` back such way in an `andThen` lambda expression.

After using your `Single.defer` lambda solution, it works like a charm:

```

Completable.complete()

.andThen(Single.defer {

val someJudge: Boolean = someData < 0L

if (someJudge) Single.error<Long>(Exception())

else Single.just(someData)

}).blockingSubscribe {

println("The number is $it")

}

```

--

--

雷哥的開發碎嘴頻道
雷哥的開發碎嘴頻道

Written by 雷哥的開發碎嘴頻道

站在人生十字路口的萌新開發者。喜歡遊戲開發與安卓App開發。擅長嘴炮與胡思亂想。

No responses yet