https://github.com/sebbekarlsson/simple-pipe
🚿 Function Composition for Python
https://github.com/sebbekarlsson/simple-pipe
composition functional-programming pipe python
Last synced: 5 months 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 (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-25T11:53:46.000Z (over 6 years ago)
- Last Synced: 2025-09-25T12:41:21.548Z (6 months 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 pipe
pipe()()
# 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 pipe
myvar = '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)