Files
30-seconds-of-code/python/s/curry.md
Angelos Chalaris 5c913d20bd Reorganize snippets
2023-05-03 21:19:02 +03:00

461 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Curry function snippet python
function
leaves-read 2020-11-02T19:27:07+02:00

Curries a function.

  • Use functools.partial() to return a new partial object which behaves like fn with the given arguments, args, partially applied.
from functools import partial

def curry(fn, *args):
  return partial(fn, *args)
add = lambda x, y: x + y
add10 = curry(add, 10)
add10(20) # 30