Last active
December 14, 2015 15:38
-
-
Save BrianHicks/5108847 to your computer and use it in GitHub Desktop.
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
sets! | |
one(1): True | |
two(2): True | |
Join/Or! | |
one_or_two(1): True | |
one_or_two(2): True | |
Intersect/And! | |
one_but_not_two(1): True | |
one_but_not_two(2): False |
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
def fset(n): | |
return lambda x: x == n | |
def set_join(*fsets): | |
return lambda x: any([f(x) for f in fsets]) | |
def set_intersect(*fsets): | |
return lambda x: all([f(x) for f in fsets]) | |
one = fset(1) | |
two = fset(2) | |
print 'sets!' | |
assert one(1) | |
assert two(2) | |
print 'one(1):', one(1) | |
print 'two(2):', two(2) | |
print 'Join/Or!' | |
one_or_two = set_join(one, two) | |
assert one_or_two(1) | |
assert one_or_two(2) | |
print 'one_or_two(1):', one_or_two(1) | |
print 'one_or_two(2):', one_or_two(2) | |
print 'Intersect/And!' | |
one_but_not_two = set_intersect(one_or_two, one) | |
assert one_but_not_two(1) | |
assert not one_but_not_two(2) | |
print 'one_but_not_two(1):', one_but_not_two(1) | |
print 'one_but_not_two(2):', one_but_not_two(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment