Last active
August 29, 2015 14:06
-
-
Save kastiglione/12a9c931658f04840f1a to your computer and use it in GitHub Desktop.
Distinct
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
- (RACSignal *)distinct { | |
return [RACSignal defer:^{ | |
NSMutableSet *set = [NSMutableSet new]; | |
NSObject *nullObject = [NSObject new]; | |
return [self filter:^(id x) { | |
x = x ?: nullObject; | |
BOOL distinct = ![set containsObject:x]; | |
if (distinct) [set addObject:x]; | |
return distinct; | |
}]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment