Skip to content

Instantly share code, notes, and snippets.

@ayberkt
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayberkt/a4d29b88c6869fe043a5 to your computer and use it in GitHub Desktop.
Save ayberkt/a4d29b88c6869fe043a5 to your computer and use it in GitHub Desktop.
Sample curried function
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))
@AntoineCezar
Copy link

Line 4 if y is not None and z is not Noneif (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 with lambda z: f(x, y, z) which is wrong.

This need some TDD love. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment