Skip to main content

Functional Utilities Library This is a Python library that provides functional utilities for writing functional-style code in Python. The library includes the following utilities:

Pipe class The Pipe class is a generic class that allows you to create a pipeline of functions that transform an input to an output. You can use the Pipe class to chain together multiple functions and apply them to an input value in a single expression. Here's an example:

from functional_utils import Pipe

def add_one(x):
    return x + 1

def double(x):
    return x * 2

result = Pipe(add_one) >> double >> double >> add_one(3)
print(result)  # Output: 23

In this example, we create a Pipe object that applies the add_one function, then the double function twice, and finally the add_one function again to an input value of 3. The output of the pipeline is 23.

pattern_match function The pattern_match function allows you to apply a transformer function based on the first predicate that matches the input value. You can use the pattern_match function to write code that selects a specific branch of execution based on the input value. Here's an example:

from functional_utils import pattern_match

def is_even(x):
    return x % 2 == 0

def is_odd(x):
    return x % 2 == 1

def double(x):
    return x * 2

def triple(x):
    return x * 3

result = pattern_match(
    [
        (is_even, double),
        (is_odd, triple),
    ],
    default=lambda x: x,
)(5)

print(result)  # Output: 15

In this example, we create a Pipe object that applies the pattern_match function to an input value of 5. The pattern_match function selects the triple function because 5 is an odd number, and applies it to the input value. The output of the pipeline is 15.

Installation You can install the library using pip:

pip install funcpipe

License This library is licensed under the MIT License.

Release files for funcpipe 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for funcpipe 0.3.0
File Size Uploaded
funcpipe-0.3.0.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for funcpipe 0.3.0
File Interpreter ABI Platform
funcpipe-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / funcpipe-0.3.0.tar.gz

Download URL funcpipe-0.3.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
155e6b374eaee9743c21d24bb2b31f7a0ff33bdfe71b92bb2ce992d0ee07dcb2
BLAKE2b-256 checksum
How to use checksums
bfad622e3350817bf3fdcc5dc6778ffb4f2429bd9472772549a43b7bef0416cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2

Release files / funcpipe-0.3.0-py3-none-any.whl

Download URL funcpipe-0.3.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0dee1df0995a706945eb2dbb74126c693191bcbafcdd8c7596ecab688bf7883e
BLAKE2b-256 checksum
How to use checksums
4a49f95da554fe90e8ec64f7fc4fb5b9b003dd6aee4703492191b24efd0a4dd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page