Rxswift: Ambiguous use of distinctUntilChanged() on Observables with optional values

Created on 6 Apr 2018  路  5Comments  路  Source: ReactiveX/RxSwift

Short description of the issue:

Calling the distinctUntilChanged() method on any observable sequence with an optional value will cause a compiler error complaining about ambiguous methods.

Expected outcome:

That the code compiles.

What actually happens:

Code does not compile, and yields error:
Ambiguous use of 'distinctUntilChanged()'

Self contained code example that reproduces the issue:

       let stringObservable: Observable<String?> = Observable<String?>.from(optional: nil)
        stringObservable.distinctUntilChanged()

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

RxSwift 4.1.2

Platform/Environment

  • [ x] iOS
  • [ ] macOS
  • [ ] tvOS
  • [ ] watchOS
  • [ ] playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • [ x] easy, 100% repro
  • [ ] sometimes, 10%-100%
  • [ ] hard, 2% - 10%
  • [ ] extremely hard, %0 - 2%

Xcode version:

Xcode 9.3 release version

Most helpful comment

Current workaround is to use:
.distinctUntilChanged({ $0 == $1 })

Proposed fix in RxSwift:
Conditional compilation for older swift versions than 4.1 for distinctUntilChanged() definition in Driver+Optional.swift and Observable+Optional.swift

All 5 comments

Current workaround is to use:
.distinctUntilChanged({ $0 == $1 })

Proposed fix in RxSwift:
Conditional compilation for older swift versions than 4.1 for distinctUntilChanged() definition in Driver+Optional.swift and Observable+Optional.swift

@Nailer we don't have Driver+Optional.swift and Observable+Optional.swift files here.

Those seem to be part of RxOptional, not RxSwift after all. And it was fixed, but not tagged.

My mistake! I didn't check this before submitting.

Closing the issue since it's fixed in RxOptional

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acecilia picture acecilia  路  3Comments

jaumard picture jaumard  路  3Comments

tyregor picture tyregor  路  3Comments

apoloa picture apoloa  路  3Comments

marlowcharite picture marlowcharite  路  3Comments