Kex
Kex

Reputation: 8599

Using distinctUntilChanged with combineLatest throws Equatable error with RxSwift

I am trying to use distinctUntilChanged with combineLatest, eg:

Observable.combineLatest(focusedCourse, infoState)
    .distinctUntilChanged()
    .map { focusedCourse, infoState in
       // Implementation
    }
    .bind(to: videoSource)
    .disposed(by: bag)

However I am getting the error:

Type '(BehaviorRelay<Course?>.Element, BehaviorRelay<InfoState>.Element)' cannot conform to 'Equatable'

I have conformed both Course and InfoState to equatable but still get this error. How can I fix this?

Upvotes: 1

Views: 1886

Answers (1)

samaitch
samaitch

Reputation: 1242

I don't think a tuple conforms to Equatable even if all its elements do so you have to provide the equality check to distinctUntilChanged:

Observable.combineLatest(focusedCourse, infoState)
    .distinctUntilChanged { $0 == $1 }
    .map { focusedCourse, infoState in
        // Implementation
    }
    .bind(to: videoSource)
    .disposed(by: bag)

Upvotes: 1

Related Questions