Skip to main content

Custom pipes

Description

This pack has some custom pipes to work with the pipe package.

This package is compatible with python 3.

Pipes

reduce

list1 = [1, 2, 3, 4, 5, 6, 7]
result = list1 | reduce(lambda a, b: a + b)

list1 = []
# raises TypeError
_ = list1 | reduce(lambda a, b: a + b)

list1 = [1]
result = list1 | reduce(lambda a, b: a + b)

fold

list1 = [1, 2, 3, 4, 5, 6, 7]
result = list1 | fold(lambda a, b: a + b, 0)

list1 = [1, 2, 3, 4, 5, 6, 7]
result = list1 | fold(lambda a, b: f"{a}/{b}" if a else f"{b}", "")

list1 = []
_ = list1 | fold(lambda a, b: f"{a}/{b}" if a else f"{b}", "")

deep_flatten

list1 = [[1,2], [3,4]]
# result is [1, 2, 3, 4]
result = list(list1 | deep_flatten())

result = list(1 | deep_flatten())
# result is [1]

list1 = [1, 2, 3, 4]
# result is [1, 2, 3, 4]
result = list(list1 | deep_flatten())

list1 = [[1,2], [3, [4, 5]]]
# result is [1, 2, 3, 4, 5]
result = list(list1 | deep_flatten())

list1 = [[1,2], [3, [4, [5, 6]]]]
# result is [1, 2, 3, 4, 5, 6]
result = list(list1 | deep_flatten())

deep_flatmap

list1:list[int] = [1, 2, 3, 4]
# result is [2, 3, 4, 5]
result = list(list1 | deep_flatmap(lambda x: x+1))

list1 = [[1, 2], [3, 4]]
# result is [2, 3, 4, 5]
result = list(list1 | deep_flatmap(lambda x: x+1))

list1 = [[1, 2], [3, [4]]]
# result is [2, 3, 4, 5]
result = list(list1 | deep_flatmap(lambda x: x+1))

result = list(1 | deep_flatmap(lambda x: x))
# result is [1]

flatten

list1 = [[1, 2], [3, 4]]
# result is [1, 2, 3, 4]
result = list(list1 | flatten())

list1 = [1, 2, 3, 4]
# raises TypeError
_ = list(list1 | flatten())

list1 = [[[1, 2]], [[3, 4]]]
# result is [[1, 2], [3, 4]]
result = list(list1 | flatten())

flatmap

list1:list = [1, 2, 3, 4]
# raises TypeError
_ = list(list1 | flatmap(lambda x: x+1))

list1 = [[1, 2], [3, [4]]]
# raises TypeError
_ = list(list1 | flatmap(lambda x: x+1))

# raises TypeError
_ = list(1 | flatmap(lambda x: x+1))

list1:list = [[1, 2], [3, 4]]
# result is [2, 3, 4, 5]
result = list(list1 | flatmap(lambda x: x+1))

as_dict

data = [(1, 2), (3, 4)]
# result {1:2, 3:4}
result = data | as_dict()

as_list

data = range(1, 5)
# result is = [1, 2, 3, 4]
result = data | as_list()

as_set

data = [1, 2, 3, 4]
# result {1, 2, 3, 4}
result = data | as_set()

split

data = [1, 2, 3, 4]
# result is ([2, 4], [1, 3])
result = data | split(lambda x: x%2==0)

invoke

data = [1, 2, 3, 4]
result = data | invoke(len)
# result is 4

foreach

data = [1, 2, 3, 4]
# prints 1, 2, 3, 4
data | foreach(print)

def increment(x):
    print(x + 1)

data = [1, 2, 3, 4]
# prints 2, 3, 4, 5
data | foreach(increment)

sliding_window

list1 = [1, 2, 3, 4, 5]
# result is [(1, 2), (2, 3), (3, 4), (4, 5)]
result = list(list1 | sliding_window(2))

list1 = [1, 2, 3, 4, 5]
# result is [(1, 2, 3), (2, 3, 4), (3, 4, 5)]
result = list(list1 | sliding_window(3))

list1 = [1, 2, 3]
# result is [(1, 2, 3)]
result = list(list1 | sliding_window(3))

list1 = [1, 2]
# result is []
result = list(list1 | sliding_window(3))

Metadata

Release files for xi-pipes 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xi-pipes 0.1.0
File Size Uploaded
xi_pipes-0.1.0.tar.gz 5.8 kB Details

Release files / xi_pipes-0.1.0.tar.gz

Download URL xi_pipes-0.1.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6f8af9599555c12a85e7a5fae3d52af56e27294412f36ff132c5971f5b1780c5
BLAKE2b-256 checksum
How to use checksums
f5ed345be6e3a5264a5f7ba0440509fadb936914867b16e86432903e388d19df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.20

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.8

2 release files

0.0.6

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page