A lightweight streaming library, similar to Java stream.
Project description
SuperStream
在用使用过 Typescript 与 Java 方便的链式调用后,回到 Python 再想实现同样的功能
高阶函数的套娃让你很痛苦吧?
性能开销都在其次,主要是写着蛋疼啊!
现在一个轻量级流式处理工具来了,利用 python 内置特性,他可以轻松实现
- 更高的可读性
- 惰性求值(无论中途map,filter多少次,数据只在最后遍历一次)
- 完善的类型提示,即使你使用 lambda
安装
直接复制 stream.py 里的代码,将来完善后上 pypi 可以使用 pip 安装,但现在还不支持
使用
与 java stream 的对照
- 暂不支持并行 parallel
- 大部分功能已支持,行为相同
主要方法支持列表
- map
- forEach
- filter
- reduce
- sorted
- limit
- skip
- count
- min/max
- distinct
- flatMap
- findAny/findFirst
- anyMatch/allMatch/noneMatch
- of
Java Stream | Python Stream | 备注 |
---|---|---|
filter | filter | |
map | map | |
mapToInt | - | 不提供 |
mapToLong | - | |
mapToDouble | - | |
flatMap | flat_map | |
flatMapToInt | - | |
flatMapToLong | - | |
flatMapToDouble | - | |
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 | - | 不常用,不会提供 |
FAQ
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
SuperStream-0.2.0.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for SuperStream-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d18a3446f47cd01002debaa958661feef40faea0e51e1d220539c3a78cc9ae87 |
|
MD5 | 5e787ee56c5317e0fa1b3aa40e5f59f3 |
|
BLAKE2b-256 | 21e3d3692398d4149a8c60677595aa081d25e8126d52d6fed87677316a2bada8 |