The distinctUntilChanged operator

The distinctUntilChanged() operator is also widely used. This operator will only allow unique contiguous elements to pass through; in other words, if the next element is equal to the previous one, it will not be allowed through:

>

This can be used with search logic to prevent executing a search twice in a row on the same search string or even on an insert statement where you want to add the login status to the local storage, and you don't want to save the same state more than once if it is the same.

Let's see the operator in action; we need to create a similar bare-bones function implementation with a disposeBag ...

Get Reactive Programming with Swift 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.