Created
May 17, 2019 13:21
-
-
Save renato04/2c47cf54480d4d9d71cfd5a8b935128e to your computer and use it in GitHub Desktop.
Python High order function samples
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
# Composistion | |
def f(x): | |
return x + 2 | |
def g(h, x): | |
return h(x) * 2 | |
print(g(f, 42)) | |
# Closure | |
def addx(x): | |
def _(y): | |
return x + y | |
return _ | |
add2 = addx(2) | |
add3 = addx(3) | |
print(add2(2), add3(3)) | |
# Currying | |
def a(x, y): | |
return x*y | |
def f2(x): | |
def _(y): | |
return (a(x, y)) | |
return _ | |
print(f2(2)) | |
print(f2(2)(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment