RxSwift
RxSwift copied to clipboard
Fix Infallible's flatMap family of operators that can return an Infallible that is not, in fact, infallible
I believe it's a big hole in the Infallible
contract because this will a) compile b) return an Infallible
that will fail silently, without calling any subscription closures (well maybe it will call onDispose[d]
, though, but that's beside the point):
_= someInfallible.flatMap { Observable.error(anError) }
subscribe(onCompleted: { print("it's not gonna call me") })
There's two ways to fix this:
- Have overloads for both variants, i.e.
- a flatMap that expects its closure to only return
Infallible
streams, and that itself returnsInfallible
. - a flatMap that expects its closure to return any
ObservableConvertibleType
and itself returnsObservable
.
- a flatMap that expects its closure to only return
- Only have the first of the above.
While 1. is better for backwards compatibility, it complicates overload resolution (Infallible
is ObservableConvertibleType
), although it seems to be working in the test code I've written.
As soon as the proposed change is agreed on, I'll add tests for the first and latest variants.
I think the fix could make sense indeed, but unfortunately it's a breaking API change so we can't easily merge it right now. It will have to wait for a later major version, but I'm keeping it open to not forget. Thanks!