Functional collections extension functions for Python
Project description
pyfuncol
A Python functional collections library. It extends collections built-in types with useful methods to write functional Python code. It uses Forbidden Fruit under the hood.
Installation
pip install pyfuncol
Usage
To use the methods, you just need to import pyfuncol. Some examples:
import pyfuncol
[1, 2, 3, 4].map(lambda x: x * 2).filter(lambda x: x > 4)
# [6, 8]
[1, 2, 3, 4].fold_left(0, lambda acc, n: acc + n)
# 10
{1, 2, 3, 4}.map(lambda x: x * 2).filter_not(lambda x: x <= 4)
# {6, 8}
["abc", "def", "e"].group_by(lambda s: len(s))
# {3: ["abc", "def"], 1: ["e"]}
{"a": 1, "b": 2, "c": 3}.flat_map(lambda kv: {kv[0]: kv[1] ** 2})
# {"a": 1, "b": 4, "c": 9}
# pyfuncol also provides some parallel operations
[1, 2, 3, 4].par_map(lambda x: x * 2).par_filter(lambda x: x > 4)
# [6, 8]
{1, 2, 3, 4}.par_map(lambda x: x * 2).par_filter(lambda x: x > 4)
# {6, 8}
{"a": 1, "b": 2, "c": 3}.par_flat_map(lambda kv: {kv[0]: kv[1] ** 2})
# {"a": 1, "b": 4, "c": 9}
API
For lists, please refer to the docs.
For dictionaries, please refer to the docs.
For sets, please refer to the docs.
For more details, please have a look at the API reference.
Documentation
See https://pyfuncol.readthedocs.io/.
Compatibility
Since it depends on Forbidden Fruit, it only works on CPython.
Contributing
See the contributing guide for detailed instructions on how to get started with the project.
License
pyfuncol is licensed under 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
File details
Details for the file pyfuncol-1.1.tar.gz
.
File metadata
- Download URL: pyfuncol-1.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1612e79306f5482ecbd7b26a08ef9b36d7a91acce25e2b1e03d7cb09721dd175 |
|
MD5 | 379f515add4296eee7b507ccb2eeacd8 |
|
BLAKE2b-256 | ba4e1c07fa001e5a2c3e0adf877470b6e8e1cf932d34143a899eaf7438b04121 |
File details
Details for the file pyfuncol-1.1-py3-none-any.whl
.
File metadata
- Download URL: pyfuncol-1.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b49203a75704150e79ec322e4c358badc9d8495f6c787097870602926393b5 |
|
MD5 | 050753cfaaeacce29c9cdaca8cea88fa |
|
BLAKE2b-256 | c3f6d3a84578f3c179ad81a90588c4b9ed9621b78ee8de79e357499f92b1b7fe |