Step into Swift logo

What is the DistinctUntilChanged Operator in RxSwift?

DistinctUntilChanged Operator

RxSwift: DistinctUntilChanged Operator


  • Prevents duplicate contiguous elements from getting through.
  • The 2nd element in the sequence will not get through.
  • Elements that are equatable can be compared or you can provide your own comparison.

Comes in 2 forms:

  • .distinctUntilChanged()
  • .distinctUntilChanged(_:)

  • .distinctUntilChanged(_:) is useful when you want to distinctly prevent duplicates for type that do not conform to equatable:
.distinctUntilChanged { a, b in a.value == b.value }



< All Posts