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
Release history Release notifications | RSS feed
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 hashes)
Built Distribution
pyChaining-0.0.2-py3-none-any.whl
(15.5 kB
view hashes)
Close
Hashes for pyChaining-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a065626ecd6049b70f15036099abb36b199159e4e6910d78cb5833ccc22604f7 |
|
MD5 | a9ac84b48c7a1c33a875247c5b7bd637 |
|
BLAKE2b-256 | 724a23c1864acfaa09c9cf90feb93ac2172a100db67bd9134d63cbd4ce5e9000 |