Files
30-seconds-of-code/snippets/curry.md
Angelos Chalaris 2973799a7d Add curry
2020-01-02 16:14:50 +02:00

383 B

title, tags
title tags
curry function,intermediate

Curries a function.

Use 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(sum, 10)

add10(20) # 30