Skip to content

Instantly share code, notes, and snippets.

@ceoro9
Created July 23, 2019 06:40
Show Gist options
  • Save ceoro9/678f14c5f00e4bb2190c6eb66212dfff to your computer and use it in GitHub Desktop.
Save ceoro9/678f14c5f00e4bb2190c6eb66212dfff to your computer and use it in GitHub Desktop.
Python Currying
# 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