Skip to main content

java stream style(high order, map reduce and method chaining) library for simplify the multiple map and filter operations

Project description

Installation

pip install xethhung/pyChaining

Usage

from pyChaining import Chains

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).list()
assert xx == [1, 2, 3, 4, 5, 6, 7]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).list()
assert xx == [1, 3, 5, 7]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).map(lambda x: x * 2).list()
assert xx == [2, 6, 10, 14]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).map(lambda x: x * 2)
    .skip(1).list()
assert xx == [6, 10, 14]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).map(lambda x: x * 2)
    .skip(2).list()
assert xx == [10, 14]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).map(lambda x: x * 2)
    .first()
assert xx == 2

xx = Chains.of([1, 2, 3, 4, 5, 6, 7]).filter(lambda x: x % 2 == 1).map(lambda x: x * 2)
    .last()
assert xx == 14

xx = Chains.of([1, 2, 3, 4, 5, 6, 7])
    .skipUntil(lambda x: x == 2).list()
assert xx == [2, 3, 4, 5, 6, 7]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7])
    .stopBefore(lambda x: x == 5).list()
assert xx == [1, 2, 3, 4]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7])
    .stopAt(lambda x: x == 5).list()
assert xx == [1, 2, 3, 4, 5]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7])
    .stopAfter(lambda x: x == 5, 1).list()
assert xx == [1, 2, 3, 4, 5, 6]

xx = Chains.of([1, 2, 3, 4, 5, 6, 7])
    .flatMap(lambda x: [x, x]).list()
assert xx == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]

xx = Chains.of([[1, 2, 3], [4, 5], [6, 7]])
    .flatten().list()
assert xx == [1, 2, 3, 4, 5, 6, 7]

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

pyChaining-0.0.2.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

pyChaining-0.0.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file pyChaining-0.0.2.tar.gz.

File metadata

  • Download URL: pyChaining-0.0.2.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for pyChaining-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f44a14e27144501d1f6d60187aa07e9faf3a69f54483ce8a28bc432fd63a11a4
MD5 afe265e1f4bcd259f5d52e9764ce9c61
BLAKE2b-256 b3ba47583e1cae5d2b9c910c14f8fb57284b1e351c3a3b71227d3d15108ae3ac

See more details on using hashes here.

File details

Details for the file pyChaining-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyChaining-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for pyChaining-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a065626ecd6049b70f15036099abb36b199159e4e6910d78cb5833ccc22604f7
MD5 a9ac84b48c7a1c33a875247c5b7bd637
BLAKE2b-256 724a23c1864acfaa09c9cf90feb93ac2172a100db67bd9134d63cbd4ce5e9000

See more details on using hashes here.

Supported by

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