Infix piping operator
Project description
ipo: Infix piping operator
Demo
from ipo import ipo, opi, head, write, p
# Ipo makes data flows much easier to follow.
ipo([5, 2, 3, 1, 4]) | sorted | opi # [1, 2, 3, 4, 5]
# Ipo comes with a shorthand for partial application:
# p(head)(3) is equivalent to functools.partial(head, 3)
ipo([5, 2, 3, 1, 4]) | p(head)(3) | list | opi # [5, 2, 3]
ipo([5, 2, 3, 1, 4]) | p(head)(3) | sorted | opi # [2, 3, 5]
ipo([5, 2, 3, 1, 4]) | sorted | p(head)(3) | list | opi # [1, 2, 3]
# Much more readable than the original!
# list(itertools.islice(sorted([5, 2, 3, 1, 4]), 3))
# You can also pipe to print directly…
ipo([5, 2, 3, 1, 4]) | sorted | p(head)(3) | list | print # [1, 2, 3]
# …or to ipo's write, which prints each line of an iterable on its own line.
ipo([5, 2, 3, 1, 4]) | sorted | p(head)(3) | list | write # 1\n2\n3
from itertools import starmap
from ipo import from_csv, skip, to_csv, before, write, p
# Ipo is ideally suited for working with CSV data.
ipo("""
#Voltage,Current
12,1
8,2
220,6
""".strip().split()) | from_csv | p(skip)(1) | \
p(starmap)(lambda v, a: (v, a, float(v) * float(a))) | \
to_csv | p(before)(["#Voltage,Current,Power"]) | write
# #Voltage,Current,Power
# 12,1,12.0
# 8,2,16.0
# 220,6,1320.0
from ipo import read, write, p
# Most ipo chains that work over iterable data are lazy by default. You can load huge files,
# process them and write the results to another file.
with open("bigfile.txt") as f_in, open("processed.txt") as f_out:
read(file=f_in) | p(map)(some_preprocessing) | \
p(map)(some_advanced_function) | \
p(map)(some_formatting) | p(write)(file=f_out)
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
ipo-2.0.0.tar.gz
(24.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ipo-2.0.0-py3-none-any.whl
(21.9 kB
view details)
File details
Details for the file ipo-2.0.0.tar.gz.
File metadata
- Download URL: ipo-2.0.0.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a51a92428a304dcecabdc7adb272f3ab813e9d4edcf6d868d1cca9644f6db389
|
|
| MD5 |
6dfcb7125def75c2cb65327436872e38
|
|
| BLAKE2b-256 |
d118e749fc28b2fac068c0f354a643042802b114cdd0bc065d38f1a30b97a41f
|
File details
Details for the file ipo-2.0.0-py3-none-any.whl.
File metadata
- Download URL: ipo-2.0.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95a052f905124c6e11f1b6a4e84b63b1f264917b631f804ca617ffb0f62530f1
|
|
| MD5 |
e3288dda92f95f0a79aecbb37c61d3e6
|
|
| BLAKE2b-256 |
2e86dbe24c0e4eb93ef929e5a7d622e5c70178132b9bb4884cb76e029b414fa3
|