Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andybrice/pypework
Functional pipeline library for Python
https://github.com/andybrice/pypework
functional functional-programming pipeline pipeline-framework pipelines pipes python syntactic-sugar
Last synced: 18 days ago
JSON representation
Functional pipeline library for Python
- Host: GitHub
- URL: https://github.com/andybrice/pypework
- Owner: andybrice
- License: mit
- Created: 2018-02-27T14:52:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-22T14:10:39.000Z (over 6 years ago)
- Last Synced: 2024-09-14T11:49:47.462Z (2 months ago)
- Topics: functional, functional-programming, pipeline, pipeline-framework, pipelines, pipes, python, syntactic-sugar
- Language: Python
- Size: 32.2 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pypework #
Pypework is a functional pipeline library for Python.
It allows you to rewrite messy nested function calls such as this:
```python
title_sanitized =
replace(replace(replace(lowercase("Lorem Ipsum Dolor 2018/02/18"), " ", "_"), "/", "-"), "@", "at")title_sanitized # -> "lorem_ipsum_dolor_2018-02-18"
```In a far more readable format like this:
```python
title_sanitized = (
"Lorem Ipsum Dolor 2018/02/18"
>> f.lowercase
>> f.replace("/", "-")
>> f.replace(" ", "_")
>> f.replace("@", "at")
)title_sanitized # -> "lorem_ipsum_dolor_2018-02-18"
```## Installation ##
Install using PIP by running:
```console
pip install pypework
```## Usage ##
Import using:
```python
import pypework
```Initialize by instantiating a Function Catcher with the current module's scope:
```python
f = pypework.FunctionCatcher(scope = __name__)
```You can now make any function call pipeable by adding `f.` before it. For example `lowercase()` becomes `f.lowercase`.
Trailing parentheses are optional if the function has only one argument.Use the `>>` operator to pipe into the function like so:
```python
"Lorem Ipsum" >> f.lowercase # -> "lorem ipsum"
```Or chain together multiple functions into a pipeline:
```python
"Lorem Ipsum" >> f.lowercase >> f.replace(" ", "_") # -> "lorem_ipsum"
```You can also split a pipeline across multiple lines if you wrap it in parentheses:
```python
(
"Lorem Ipsum"
>> f.lowercase
>> f.replace(" ", "_")
)# -> "lorem_ipsum"
```Or by adding trailing backslashes:
```python
"Lorem Ipsum" \
>> f.lowercase \
>> f.replace(" ", "_")# -> "lorem_ipsum"
```