Skip to main content

Use partial function application in Python

Project description

Pypartial is a simple Python library that allows the use of partial function application notation in native Python. It is extremely useful when trying to write concise and clear code, and extends the ease offered by Python’s functional programming features.

Example:

import pypartial #use <_ notation to partial apply functions

binary = int<_(base=2) #you can pass keyword arguemnts print(binary(‘101010100101’))

import random dice=random.randint<_(1, 6) #you can also pass non-keywords print(dice()) print(dice())

up_to_ten = range<_(_, 11) #you can leave args blank with ‘_’ print(list(up_to_ten(5)))

import operator double = operator.mul<_(2) print(double(7))

class Foo(object):
def bar(self, a, b):

print([a,b])

def egg(self, a, b, c=9):

print([a,b,c])

foo=Foo() bar7 = foo.bar<_(_, b=7) #works with methods too bar7(2)

egg1 = foo.egg<_(_, 5) egg2 = egg1<_(c=9) #you can partially apply multiple times egg2(6)

print(egg2) #nice string representation

Project details


Download files

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

Source Distribution

pypartial-1.0.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

pypartial-1.0.3-py2.py3-none-any.whl (3.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pypartial-1.0.3.tar.gz.

File metadata

  • Download URL: pypartial-1.0.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypartial-1.0.3.tar.gz
Algorithm Hash digest
SHA256 00f136d02ff67c3f3031fa6af7649a9f06d0b953e5906907e582d67dc6c37e9f
MD5 18cc3a7b026786ec9946a2fc3534d483
BLAKE2b-256 4ad264ff730b41463f0bc972e2799a909015e6a72a4bffabddc77a10b4e6a544

See more details on using hashes here.

File details

Details for the file pypartial-1.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pypartial-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0342efecf5a8dac280e3f2891acd780550b17ac9df7a8e2439c48a5ff4461fc9
MD5 0a8ccdb8eff0db0a55484355c2764c7c
BLAKE2b-256 1a3a924cbdb4ca61e78befc4a647838a29de12bc1dde086a15dbe16da2a92dd7

See more details on using hashes here.

Supported by

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