Files
30-seconds-of-code/snippets/curry.md
2022-06-09 13:00:34 +03:00

504 B

title, tags, expertise, cover, firstSeen, lastUpdated
title tags expertise cover firstSeen lastUpdated
Curry function function intermediate blog_images/leaves-read.jpg 2020-01-02T16:14:50+02:00 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