Skip to main content

Additional functional tools for python not covered in the functools library

Project description

Functools Extra

PyPi Supported Python versions Ruff

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

The project is built with poetry. Check out the project and run

poetry install

to install the dependencies. After that you can run

poetry run pytest tests

to run the tests,

poetry run ruff format functools_extra tests --check

to check that the code is formatted correctly,

poetry run ruff format functools_extra tests

to format your code with ruff and

poetry run ruff check functools_extra tests

to lint the project.

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

functools_extra-0.2.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

functools_extra-0.2.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

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