Created
July 23, 2019 06:40
-
-
Save ceoro9/678f14c5f00e4bb2190c6eb66212dfff to your computer and use it in GitHub Desktop.
Python Currying
This file contains hidden or 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
# Demonstrate Currying of composition of function | |
def change(b, c, d): | |
def a(x): | |
return b(c(d(x))) | |
return a | |
def kilometer2meter(dist): | |
""" Function that converts km to m. """ | |
return dist * 1000 | |
def meter2centimeter(dist): | |
""" Function that converts m to cm. """ | |
return dist * 100 | |
def centimeter2feet(dist): | |
""" Function that converts cm to ft. """ | |
return dist / 30.48 | |
if __name__ == '__main__': | |
transform = change(centimeter2feet, meter2centimeter, kilometer2meter ) | |
e = transform(565) | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment