Last active
August 29, 2015 14:08
-
-
Save agos/4bee946e973fa726852e 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
identity = lambda x: x | |
compose = lambda f, g: lambda x: g(f(x)) | |
# Test identity function | |
print identity(3) is 3 | |
# Test composition | |
increment = lambda x: x + 1 | |
double = lambda x: x * 2 | |
print compose(increment, double)(3) | |
print compose(double, increment)(3) | |
# Test composition respects identity | |
five = lambda x: 5 | |
print five("WAT") is compose(identity, five)("WAT") | |
print five("WAT") is compose(five, identity)("WAT") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment