Minimalist Currying implementation for Python
Project description
kare
Minimal implementation of Function Currying for python.
Usage
You can curry any callable by applying the curry function to it:
from kare import curry
def my_sum(x: int, y: int, z: int) -> int:
return x + y + z
curried_sum = curry(my_sum)
Curried functions take a single argument and return either a new function that takes a single argument or the result of applying all the arguments passed so far to the original function:
sum_two = curried_sum(2)
sum_five = sum_two(3)
sum_five(1) # == 6, equivalent to my_sum(2, 3, 1)
If you chain multiple calls together for a more succint notation:
sum_five = curried_sum(2)(3)
The curry function also works as a decorator:
@curry
def my_curried_sum(x: int, y: int, z: int) -> int:
return x + y + z
add_six = my_curried_sum(2)(4)
Currently we only support functions with positional and specified number of arguments. The following:
@curry # This wil raise an exception
def variadic_positional_function(*args):
...
@curry # This wil raise an exception
def variadic_positional_function(*, x: int, y: int):
...
@curry # This wil raise an exception
def variadic_positional_function(x: int, y: int, **kwargs):
...
If you need to do partial application on keyword arguments you can use functools' partial as usual.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kare-0.0.1.tar.gz.
File metadata
- Download URL: kare-0.0.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.12 Darwin/20.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
908d8a58db8f540dcc9d3f872f5e2bd8bf60bb1a76f28dec361d6d930e8e8ec5
|
|
| MD5 |
eca42b81f5f6504aa4b4784e00652d74
|
|
| BLAKE2b-256 |
f47083a098f404d34d87d8176b2703d8bb3ada6c9ffbeba8720e7a186f93b61d
|
File details
Details for the file kare-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kare-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.12 Darwin/20.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19a681d25a60934956574f6e2a2a53440e320923930c3e5593cdfe55de2818ba
|
|
| MD5 |
9b91d9e3ec217b3e05b15627441a46c6
|
|
| BLAKE2b-256 |
c65c9abf78d6821c9447140a2288f47911bf44f4697b245aacdc60ec78e6bdc8
|