Last active
August 29, 2015 14:24
-
-
Save ayberkt/a4d29b88c6869fe043a5 to your computer and use it in GitHub Desktop.
Sample curried function
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 curried_f(x, y=None, z=None): | |
def f(x, y, z): return x**3 + y**2 + z | |
if y is not None and z is not None: | |
return f(x, y, z) | |
if y is not None: | |
return lambda z: f(x, y, z) | |
return lambda y, z=None: f(x, y, z) if (y is not None and z is not None) else (lambda z: f(x, y, z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 4
if y is not None and z is not None
if (y is not None and z is not None)` they are the exact same condition and since line 5 is a return line 9 condition will never happen.What if I use
curried_f(2, z=3)
? Looks like I will end withlambda z: f(x, y, z)
which is wrong.This need some TDD love. ^_^