Last active
October 9, 2015 18:11
-
-
Save skyylex/8186835574fb56908a1c to your computer and use it in GitHub Desktop.
More common way to distinguish values in the RACSignal stream (ReactiveCocoa 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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