Logo

Programming-Idioms

History of Idiom 37 > diff from v38 to v39

Edit summary for version 39 by do:
[Python] missing closing bracket

Version 38

2019-02-02, 06:14:44

Version 39

2019-09-26, 16:59:21

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Extra Keywords
curry
Extra Keywords
curry
Imports
from functools import partial
Imports
from functools import partial
Code
def f(a):
	def add(b):
		return a+b
	return add

print (f(2)(1)

#add_to_two = partial(f, 2)
Code
def f(a):
	def add(b):
		return a+b
	return add

print (f(2)(1))

#add_to_two = partial(f, 2)
Doc URL
https://docs.python.org/3/library/functools.html#functools.partial
Doc URL
https://docs.python.org/3/library/functools.html#functools.partial