Utility functions for common tasks when composing functions.
Project description
composetools
Utility functions for Pythonic function composition.
BYO compose()
implementation.
Install
pip install composetools
Examples
from funcy import compose, rcompose
from composetools import unique, flat, sort
# Get unique items from nested iterables.
compose(sort, flat, unique)([[1, 2, 3], [4, 3, 2]]) # [1, 2, 3, 4]
# Get lines of a file.
from pathlib import Path
get_lines = rcompose(
Path,
Path.expanduser,
Path.resolve,
Path.read_text,
str.splitlines,
)
get_lines("~/.gitconfig")
Functions
tap
- Call a function but don't return the result, eg.tap(lambda x: print(x))(4) == 4
each
- Curried version ofmap
.keep
- Curried version offilter
.drop
- Curried version ofitertools.filterfalse
.sort
- Curried version ofsorted
.flat
- Flatten an arbitrarily nested iterable.unique
- Yield unique items of an iterable.
Develop
$ git clone https://github.com/SeparateRecords/python-composetools
$ poetry install
$ poetry run tests
Licence
ISC
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
composetools-0.1.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for composetools-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d873187d67aa4b20653eee984576a1fd6ef0bd5855c1fa8e7335a7cc88149f3 |
|
MD5 | 55c5e22d6eb8f7c9e06a873943db41ab |
|
BLAKE2b-256 | 16b3524980000a96d2af1cea252ee062d1960e9f3d8a3dfca9a7f280fa0dd9a4 |