Skip to content

Instantly share code, notes, and snippets.

@skyylex
Last active October 9, 2015 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyylex/8186835574fb56908a1c to your computer and use it in GitHub Desktop.
Save skyylex/8186835574fb56908a1c to your computer and use it in GitHub Desktop.
More common way to distinguish values in the RACSignal stream (ReactiveCocoa 2)
typedef BOOL(^PassRuleBlock)(id first, id second);
- (RACSignal *)distinctBasedOnRule:(PassRuleBlock)passRuleBlock {
Class class = self.class;
return [[self bind:^{
__block id lastValue = nil;
return ^(id x, BOOL *stop) {
if ((passRuleBlock(x, lastValue) == NO)) { return [class empty]; }
lastValue = x;
return [class return:x];
};
}] setNameWithFormat:@"[%@] -distinctBasedOnRule", self.name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment