Additional functional tools for python not covered in the functools library
Project description
Functools Extra
Additional functional tools for python not covered in the functools library.
Installation
pip install functools-extra
How to use
Pipes
A pipe is a function that takes a value and list of functions and calls them in order.
So foo(bar(value))
is equivalent to pipe(value, bar, foo)
.
You can use built-in functions like list
, special operators from the operator module or custom functions.
All type-hints are preserved.
from functools_extra import pipe
from operator import itemgetter
def add_one(x: int) -> int:
return x + 1
assert pipe(range(3), list, itemgetter(2), add_one) == 3
Or you can use pipe_builder
to create a reusable pipe:
from functools_extra import pipe_builder
def add_one(x: int) -> int:
return x + 1
def double(x: int) -> int:
return x * 2
add_one_and_double = pipe_builder(add_one, double)
assert add_one_and_double(1) == 4
assert add_one_and_double(2) == 6
Development
This project is using Rye. Check out the project and run
rye sync
to create a virtual environment and install the dependencies. After that you can run
rye run test
to run the tests,
rye run lint
to check the linting,
rye run fix
to format the project with ruff and fix the fixable errors.
License
This project is licensed under the terms of the MIT license.
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
Built Distribution
Hashes for functools_extra-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de0b5013c6f8dc9569be8bbd9ed9143c8aa2a9e30f1a09b2eba394062be215b |
|
MD5 | 16e27d178b1deeaf15f8d99e15149d08 |
|
BLAKE2b-256 | 0b121ad0a74d0dcafb323f1c1e40e7586e56a156ac48488d37b3b8efeb5a5617 |