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.
-[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..
Most helpful comment
@wdcurry The Swift API calls it
skipRepeats
instead.