Skip to main content

A lightweight streaming library, similar to Java stream.

Project description

SuperStream

Test codecov Python 3.6+ Software License image

在用使用过 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

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

SuperStream-0.2.6.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

SuperStream-0.2.6-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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