Skip to main content

autopartial

Project description

Autopartial

This is a simple library that provides a decorator that allows your to apply a function partially. In other words, it allows you to curry a function with some of its arguments, from left to right.

Installation

After cloning this repository, you can install the package by running the following command in the root directory of the repository:

pip install -e .

Usage and example

The main use case is to decorate a function definition with @autopartial.

An example can is in main.py. It contains the following code:

from autopartial import autopartial

@autopartial
def add(x, y):
	return x + y

if __name__ == '__main__':
	x = 10
	y = 20

	add_10 = add(x)	 # add(x): y -> x + y
	print(add_10(y)) # 30

Here, the add function takes 2 arguments and returns its sum. You can now partially apply the argument x to add by calling add(x). This returns a new function that takes only one argument y and returns x + y.

In the example above, add(10) returns a function add_10 that always adds 10 to its input.

You can run this example, after installing this package, by running the following command from the root of the repository:

python main.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autopartial-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file autopartial-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: autopartial-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for autopartial-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6e305de0f6e10a521c64ac38499d6a2a4053b2383f34e09871c31dfc2a1331
MD5 9071aa9ab2ad3f6ee9750418e9c35177
BLAKE2b-256 1ee8a8af3dc87e6dad85ae17ca7d81f5529681ae44de09e5e734c51717f85af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page