Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Signal for unique values only #1286

Closed
fatuhoku opened this issue Apr 28, 2014 · 8 comments
Closed

Question: Signal for unique values only #1286

fatuhoku opened this issue Apr 28, 2014 · 8 comments
Labels

Comments

@fatuhoku
Copy link

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.

@jspahrsummers
Copy link
Member

-[RACSignal distinctUntilChanged]

@fatuhoku
Copy link
Author

Top notch response time. Thank you @jspahrsummers =]

@conradwt
Copy link

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

@jspahrsummers
Copy link
Member

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.

@fatuhoku
Copy link
Author

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.

@wdcurry
Copy link

wdcurry commented Nov 25, 2014

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.

@jspahrsummers
Copy link
Member

@wdcurry The Swift API calls it skipRepeats instead.

@wdcurry
Copy link

wdcurry commented Nov 26, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants