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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.