Skip to content

Commit 47f4ac0

Browse files
committed
Adding currying
1 parent 725f54c commit 47f4ac0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [Shortest Path to Get Food](solutions/shortest-path-to-get-food/README.md) `Python` `Graph`
4949

5050
### Python Tips
51+
- [Currying](python_utils/currying/README.md)
5152
- [Debugging with pdb](python_utils/pdb/README.md)
5253
- [Decorator](python_utils/decorator/README.md)
5354
- [Format](python_utils/format/README.md)

python_utils/currying/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Currying
2+
- Currying is the process of transforming a function that takes multiple arguments into a series of functions that each take a single argument. In Python, this can be achieved through nested functions.
3+
4+
#### Examples
5+
- [Code](multiply.py)
6+
7+
8+
### [Back](../../README.md)

python_utils/currying/multiply.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Callable
2+
3+
def mutiply_setup(a: float) -> Callable:
4+
def mutiply(b: float) -> float:
5+
return a * b
6+
return mutiply
7+
8+
double: Callable = mutiply_setup(2)
9+
triple: Callable = mutiply_setup(3)
10+
11+
print(f'{double(100) = }')
12+
print(f'{triple(100) = }')

0 commit comments

Comments
 (0)