Files
30-seconds-of-code/snippets/curry.md
Isabelle Viktoria Maciohsek e62b22659d Update snippet titles
2022-02-13 13:53:22 +02:00

24 lines
458 B
Markdown

---
title: Curry function
tags: function,intermediate
firstSeen: 2020-01-02T16:14:50+02:00
lastUpdated: 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.
```py
from functools import partial
def curry(fn, *args):
return partial(fn, *args)
```
```py
add = lambda x, y: x + y
add10 = curry(add, 10)
add10(20) # 30
```