Answer the question
In order to leave comments, you need to log in
What is currying (currying) used for in real tasks?
Hello!
I recently learned about such a thing as currying , in Python, currying in the simplest case can be written like this:
f = lambda y: lambda x: x + y
print f(2)(2)
Answer the question
In order to leave comments, you need to log in
Suppose there is a function that takes many parameters and the first parameter is the form class name (in django)
def cool_staff(form_class, inits, defaults, user, other_param):
# много строчек кода
...
res = cool_staff(form_class=MainForm, inits={a:1, b:3}, defaults=[1,2,3], ...)
...
res = cool_staff(form_class=MainForm, inits={a:100500, b:42}, defaults=[3,2,1], ...)
...
...
res = main_cool_staff(inits={a:1, b:3}, defaults=[1,2,3], ...)
...
res = main_cool_staff(inits={a:100500, b:42}, defaults=[3,2,1], ...)
...
import functools
main_cool_staff = functools.partial(cool_staff, MainForm)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question