SuperStream
在用使用过 Typescript 与 Java 方便的链式调用后,回到 Python 再想实现同样的功能 高阶函数的套娃让你很痛苦吧? 性能开销都在其次,主要是写着蛋疼啊!
现在一个轻量级流式处理工具来了,利用 python 内置特性,他可以轻松实现
- 更高的可读性
- 惰性求值(无论中途map,filter多少次,数据只在最后遍历一次)
- 完善的类型提示,即使你使用 lambda
安装
pip install superstream
使用
与 java stream 的对照
- 暂不支持并行 parallel
- 大部分功能已支持,行为相同
主要方法支持列表
- map
- forEach
- filter
- reduce
- sorted
- limit
- skip
- count
- min/max
- distinct
- flatMap
- findAny/findFirst
- anyMatch/allMatch/noneMatch
- of
- collect(toList/toSet/toMap/groupingBy)
| Java Stream | Python Stream | 备注 |
|---|---|---|
| filter | filter | |
| map | map | |
| flatMap | flat_map | |
| collect | collect | |
| collect(groupingBy) | group_by | |
| collect(toList) | to_list | |
| collect(toSet) | to_set | |
| collect(toMap) | to_dict | |
| collect(toMap) | to_map | to_dict 的别名,保持与 Java 的一致 |
| distinct | distinct | |
| sorted | sorted | |
| peek | - | peek 在 java stream 多为调试功能, python stream 将不会实现,可用 map 并返回元素本身代替 |
| limit | limit | |
| skip | skip | |
| forEach | for_each | |
| reduce | reduce | |
| count | count | |
| min | min | |
| max | max | |
| findAny | find_first | findAny 可用 findFirst 代替 |
| findFirst | find_first | |
| anyMatch | any_match | |
| noneMatch | none_match | |
| allMatch | all_match | |
| of | of | |
| empty | - | 我在业务中没用过这个方法,如果有需要我会提供 |
| iterate | - | 不常用,不会提供 |
| generate | - | 不常用,不会提供 |
| concat | - | 不常用,不会提供 |
| mapToInt | - | 不提供 |
| mapToLong | - | 不提供 |
| mapToDouble | - | 不提供 |
| flatMapToInt | - | 不提供 |
| flatMapToLong | - | 不提供 |
| flatMapToDouble | - | 不提供 |
FAQ
Metadata
Release files for SuperStream 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| SuperStream-0.2.6.tar.gz | 5.0 kB | Without provenance | Details for SuperStream-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| SuperStream-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for SuperStream-0.2.6-py3-none-any.whl |
Total release size: 10.4 kB
Release files / SuperStream-0.2.6.tar.gz
| Download URL | SuperStream-0.2.6.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b3000ef3a3d1bc912e756ec13ff3a2bbe09fb9667038c1d9225079cf3f749ae
|
|
BLAKE2b-256 checksum How to use checksums |
f994c3617622a2896ed66f583d7cccf442448080854bc70b7df03d308f58b72e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.2
|
Release files / SuperStream-0.2.6-py3-none-any.whl
| Download URL | SuperStream-0.2.6-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bbc8fe7fa252359d3471ca7b0bba32501194f22ae89018cc3eac8a5e81ab170
|
|
BLAKE2b-256 checksum How to use checksums |
85ef86991d75fff5512784c5846cab064804e43ae675bea70e3f607cb453e1d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.2
|
Security for SuperStream 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.