Last active
December 16, 2015 18:09
-
-
Save kastiglione/5475944 to your computer and use it in GitHub Desktop.
Compose a signal corresponding to whether a source signal has sent an equal number of YESes and NOs.
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
[[[signal | |
// Map YES to 1, NO to -1 | |
map:^(NSNumber* b) { | |
return @(b.boolValue ? 1 : -1); | |
}] | |
// Running sum of yes/1's and no/-1's | |
startWithScan:@0 combine:^(NSNumber* running, NSNumber* next) { | |
return @(running.intValue + next.intValue); | |
}] | |
// A 0-sum means equal number of YES/NO's; Map 0 to YES | |
map:^(NSNumber* sum) { | |
return @(sum.intValue == 0); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment