Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeertmans/flpy
Functional but Lazy Python
https://github.com/jeertmans/flpy
Last synced: 30 days ago
JSON representation
Functional but Lazy Python
- Host: GitHub
- URL: https://github.com/jeertmans/flpy
- Owner: jeertmans
- License: mit
- Created: 2021-10-22T13:20:32.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-25T19:08:42.000Z (11 months ago)
- Last Synced: 2024-10-04T09:51:20.029Z (about 2 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/jeertmans/flpy/main.svg)](https://results.pre-commit.ci/latest/github/jeertmans/flpy/main) [![PyPI version](https://badge.fury.io/py/flpy.svg)](https://badge.fury.io/py/flpy) [![Documentation Status](https://readthedocs.org/projects/flpy/badge/?version=latest)](https://flpy.readthedocs.io/en/latest/?badge=latest)
# Functional, but Lazy Python
With **FLPy**, improve the readibility of your programs by leveraging functional programming.
### Installation
**FLPy** has no external dependencies, and can be installed using `pip`:
```
pip install flpy
```### Examples
Given an input sequence `x`, print all, but the first, squared values that are divisible by 3 and collect the result into a list.
```python>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Input sequence
# Usual way
>>> squares = map(lambda v: v * v, x)
>>> squares_div_by_3 = filter(lambda v: v % 3 == 0, squares)
>>> y = list(squares_div_by_3)[1:] # We skip one value
>>> for v in y:
... print(v)
36
81
>>> y
[36, 81]# FLPy way
>>> from flpy import It
>>> y = (
... It(x)
... .map('|v| v * v') # You can also use lambda or any other callable
... .filter('|v| v % 3 == 0')
... .skip(1)
... .collect() # Collects the iterator into a list
... .for_each('|v| print(v)') # Yet it still returns the list to `y`
... )
36
81
>>> y
ItA<[36, 81]>
```### TODOs
Non-exhaustive list of ideas.
1. Implement parallel iterators
2. Add kwargs support for built-in functions
3. Increase # of examples
4. Improve docs
5. Write contribution guidelines
6. Setup mypy
7. Add unitary tests
8. Add benchmarks vs. pure Python to measure overhead
9. Add support for async iterators
10. ...