Reactivecocoa: Question: Signal for unique values only

Created on 29 Apr 2014  路  8Comments  路  Source: ReactiveCocoa/ReactiveCocoa

I want to filter values based on the Suppose I have a signal

RACSignal *original = ...;   // sends values [1,1,2,2,3,3,3,3,3,3,3,4,4,4,3,3,1,2]

How can I create a signal filtered such that it sends values of s only if it's changed from the previous value? i.e.

RACSignal *filtered = [original ...];  // sends values [1, 2, 3, 4, 3, 1, 2]

My RAC intuition tells me I can do this with one of those mapWithPrevious: or whatever methods, but I'm not very sure how they're used.

question

Most helpful comment

@wdcurry The Swift API calls it skipRepeats instead.

All 8 comments

-[RACSignal distinctUntilChanged]

Top notch response time. Thank you @jspahrsummers =]

@jspahrsummers Would it a good idea to add this Q/A to the filtering or appropriate section of the online documentation?

The operator itself is documented, and it's used in a lot of examples and past Q&A. I'm not sure where else we could fit it in.

Well I hope this question and answer serves as documentation enough that users looking for 'unique values' will be pointed to this very useful operator.

new to RAC, liking its potential, totally not getting the context of the name "distinctUntilChanged" .. It almost seems like it needs to be oppositely named. As it returned a distinct value _when_ the the value changes to another value, it might actually be distinctWhenChanged. I can learn to understand it of course, but is ain't intuitive.

@wdcurry The Swift API calls it skipRepeats instead.

Thanks @jspahrsummers .. now that is more immediately understandable..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrettThePark picture BrettThePark  路  4Comments

mdiep picture mdiep  路  5Comments

gabro picture gabro  路  5Comments

v-silin picture v-silin  路  4Comments

simonxcheng picture simonxcheng  路  6Comments