Skip to main content

Custom pipes

Project description

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)

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

xi_pipes-0.0.6.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xi_pipes-0.0.6-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file xi_pipes-0.0.6.tar.gz.

File metadata

  • Download URL: xi_pipes-0.0.6.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for xi_pipes-0.0.6.tar.gz
Algorithm Hash digest
SHA256 45b228b80c5b4ec3a517f3c33eb31c5ae56719ff99278079e1934d2d86375d16
MD5 cb4ff4190b5aa58eed52c6779171265c
BLAKE2b-256 7234a496579bdde534c4157e2759ce93c679d4c091a82392389dfdc319592b6e

See more details on using hashes here.

File details

Details for the file xi_pipes-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: xi_pipes-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for xi_pipes-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 07fe5e5c056a199b91b78b53ef756f5337467f29f9ffb6eeb750ade452ad0141
MD5 4bfc53004feeb151d3d4c598ca72eff0
BLAKE2b-256 2265ae20beb5f90310cc1881e48e2536374cbe282de7a552b484597617c0d70f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page