Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebbekarlsson/simple-pipe
🚿 Function Composition for Python
https://github.com/sebbekarlsson/simple-pipe
composition functional-programming pipe python
Last synced: 7 days ago
JSON representation
🚿 Function Composition for Python
- Host: GitHub
- URL: https://github.com/sebbekarlsson/simple-pipe
- Owner: sebbekarlsson
- License: gpl-3.0
- Created: 2017-12-03T16:39:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-25T11:53:46.000Z (over 5 years ago)
- Last Synced: 2024-12-31T10:07:55.774Z (about 1 month ago)
- Topics: composition, functional-programming, pipe, python
- Language: Python
- Size: 22.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Pipe Function Composition for Python!
> pipe methods in Python!## Usage:
```python
from simple_pipe import pipepipe()()
# your input variable will go through all the methods,
# and then the pipe method will return the final modified variable.
```## Example:
```python
from simple_pipe import pipemyvar = 'hello world'
print(pipe(lambda x: x.title(), lambda x: x.replace(' ', ''))(myvar))
>> HelloWorld
```> You can also create re-usable `compositions` like this:
```python
objects = [{'name': 'John'}, {'name': 'Lisa'}, {'Name': 'Eric'}]composition = pipe(
lambda x: safe_set_attribute(x, 'age', 21),
lambda x: safe_set_attribute(x, 'color', 'green')
)objects = [composition(obj) for obj in objects]
print(objects)
>> [
{'name': 'John', 'age': 21, 'color': 'green'},
{'name': 'Lisa', 'age': 21, 'color': 'green'},
{'Name': 'Eric', 'age': 21, 'color': 'green'}
]
```## Install
> Run:pip install simple-pipe
> or ...
* Clone down the repository
> And then execute:
python setup.py install
## Running Unit Tests
pip install pytest
pytest .## License
> [GPL 3.0](gpl-3.0.md)