You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

kare

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kare

Minimalist Currying implementation for Python

0.0.1
pipPyPI
Maintainers
1

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.

Keywords

functional

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts