Closed thomasnield closed 6 years ago
These extensions also collide in such case:
val toMaybe1: Maybe<Unit> = Single.just(Unit).toMaybe()
val toMaybe2: Maybe<Observable<Unit>> = Observable.just(Unit).toMaybe()
I'm following up on this stuff this weekend
It seems these 2 following extensions collide with each other.
fun <T : Any> T?.toMaybe(): Maybe<T> = Maybe.create { s -> if (this != null) s.onSuccess(this); s.onComplete() }
fun <T : Any> (() -> T).toMaybe(): Maybe<T> = Maybe.fromCallable(this)
I'm unable to use the latter to apply .toMaybe()
to a lambda so that it is the same as calling Maybe.fromCallable(lambda)
. Compiler always resolves it to the former extension.
val myInt: Int? = null
{ myInt }.toMaybe() // compiler resolves this to use the former extension function
// i.e. it produces Maybe<() -> Int?>
Yes, they both need to go away, all toMaybe()
and toSingle()
extensions.
😠I loved .toSingle()
@alexbirkett you can always implement it on your own domain. These extensions were highly problematic and clashed with other libraries that put toMaybe() and toSingle() on specific types.
We really should remove the following extensions:
https://github.com/ReactiveX/RxKotlin/blob/2.x/src/main/kotlin/io/reactivex/rxkotlin/single.kt#L9 https://github.com/ReactiveX/RxKotlin/blob/2.x/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt#L9
I'm finding these quickly clash with other libraries and domains that have specialized types with good reason to have
toSingle()
andtoMaybe()
. For instance, a JavaFX popupDialog
could be extended to return aMaybe
emitting the users response. AtoMaybe()
would be the natural name for this but it clashes with RxKotlin, and it is definitely clashing with RxKotlinFX.Therefore, let's remove any extension functions targeting a general, single
T
type.