Add curry

This commit is contained in:
Angelos Chalaris
2020-01-02 16:14:50 +02:00
parent 37f433feb7
commit 2973799a7d

22
snippets/curry.md Normal file
View File

@ -0,0 +1,22 @@
---
title: curry
tags: function,intermediate
---
Curries a function.
Use `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(sum, 10)
add10(20) # 30
```