Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DistinctUntilChanged with boolean tuple behaves unexpectedly #2097

Closed
2 of 17 tasks
mickamy opened this issue Oct 31, 2019 · 1 comment
Closed
2 of 17 tasks

DistinctUntilChanged with boolean tuple behaves unexpectedly #2097

mickamy opened this issue Oct 31, 2019 · 1 comment

Comments

@mickamy
Copy link

mickamy commented Oct 31, 2019

Short description of the issue:

Observable<(Bool, Bool)>.distinctUntilChanged behaives unexpectedly.

Observable<(Bool, Bool)>
    .of(
      (false, false),
      (true, false),
      (false, true),
      (true, true)
    )
    .distinctUntilChanged { $0 == $1 }
    .subscribe(onNext: { print("onNext: \($0)") })
    .disposed(by: bag)

Expected outcome:

onNext: (false, false)
onNext: (true, false)
onNext: (false, true)
onNext: (true, true)

What actually happens:

onNext: (false, false)
onNext: (true, false)
onNext: (true, true)

Self contained code example that reproduces the issue:

See above.
I also made a project for this.
https://github.com/mickamy/DistinctUntilChangedBugExample

This is not an issue belongs to Swift language I think.

print((false, false) == (true, false)) // false
print((true, false) == (false, true)) // false
print((false, true) == (true, true)) // false

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

$ cat Podfile.lock
PODS:
  - RxCocoa (5.0.1):
    - RxRelay (~> 5)
    - RxSwift (~> 5)
  - RxRelay (5.0.1):
    - RxSwift (~> 5)
  - RxSwift (5.0.1)

DEPENDENCIES:
  - RxCocoa (~> 5)
  - RxSwift (~> 5)

SPEC REPOS:
  https://github.com/cocoapods/specs.git:
    - RxCocoa
    - RxRelay
    - RxSwift

SPEC CHECKSUMS:
  RxCocoa: e741b9749968e8a143e2b787f1dfbff2b63d0a5c
  RxRelay: 89d54507f4fd4d969e6ec1d4bd7f3673640b4640
  RxSwift: e2dc62b366a3adf6a0be44ba9f405efd4c94e0c4

PODFILE CHECKSUM: 1d020afcc2b600eb5b35469eadd8d975ae798179

COCOAPODS: 1.7.2

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

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

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

Xcode version:

$ xcodebuild -version
Xcode 11.1
Build version 11A1027

⚠️ Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@mickamy
Copy link
Author

mickamy commented Oct 31, 2019

Observable<(Bool, Bool)>
    .of(
        (false, false),
        (true, false),
        (false, true),
        (true, true)
    )
    .distinctUntilChanged({ $0 as (Bool, Bool) == $1 as (Bool, Bool) })
    .subscribe(onNext: { print("onNext: \($0)") })
    .disposed(by: bag)
onNext: (false, false)
onNext: (true, false)
onNext: (false, true)
onNext: (true, true)

Sorry it was Swift lang issue.

Somehow == in comparer { $0 == $1 } is taken as func == (lhs: Bool, rhs: Bool) -> Bool, which should be func == <A, B>(lhs: (A, B), rhs: (A, B)) -> Bool where A : Equatable, B : Equatable thou.

Gonna close this issue.

@mickamy mickamy closed this as completed Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant