No project description provided
Project description
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.
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
File details
Details for the file funcpipe-0.3.0.tar.gz
.
File metadata
- Download URL: funcpipe-0.3.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 155e6b374eaee9743c21d24bb2b31f7a0ff33bdfe71b92bb2ce992d0ee07dcb2 |
|
MD5 | e2f9bd09f73c89a7fb25d35f18c4b38b |
|
BLAKE2b-256 | bfad622e3350817bf3fdcc5dc6778ffb4f2429bd9472772549a43b7bef0416cf |
File details
Details for the file funcpipe-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: funcpipe-0.3.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dee1df0995a706945eb2dbb74126c693191bcbafcdd8c7596ecab688bf7883e |
|
MD5 | 4cdc06eb94f62548dfe308bf82afa679 |
|
BLAKE2b-256 | 4a49f95da554fe90e8ec64f7fc4fb5b9b003dd6aee4703492191b24efd0a4dd7 |