Java like streams for snakes
Project description
Snakestream
Java like streams for snakes
This is a python streaming api with witch you can get a similar experience as with the Java streams api from Java 8. There is no feature parity, what has been done so far is a beginning, and we will see where the road takes us.
Features
- Create a stream from a List, Generator or AsyncGenerator.
- Process your stream with both synchronous or asynchronous functions.
- map()
- filter()
- flat_map()
- sorted()
- distinct()
- peek()
- Terminal functions include:
- collect()
- reduce()
- for_each()
- max()
- min()
- find_fist()
- all_match()
Observe
This library is currently under heavy development and there will be breakage in the current phase. When version 1.0.0 is realeased, only then will backwards compatability be the top priority. Please refer to Migration.
Usage
A simple int stream with .map()
and .filter()
import asyncio
from snakestream import stream_of
from snakestream.collector import to_generator
int_2_letter = {
1: 'a',
2: 'b',
3: 'c',
4: 'd',
5: 'e',
}
async def async_int_to_letter(x: int) -> str:
await asyncio.sleep(0.01)
return int_2_letter[x]
async def main():
it = stream_of([1, 3, 4, 5, 6]) \
.filter(lambda n: 3 < n < 6) \
.map(async_int_to_letter) \
.collect(to_generator)
async for x in it:
print(x)
asyncio.run(main())
Then in the shell
~/t/test> python test.py
d
e
Migration
These are a list of the known breaking changes. Until release 1.0.0 focus will be on implementing features and changing things that does not align with how streams work in java.
- 0.0.5 -> 0.0.6: The
stream()
function has been renamedstream_of()
. So rename all imports of that function, and it should be OK - 0.1.0 -> 0.2.0: The
unique()
function has been renameddistinct()
. So rename all imports of that function, and it should be OK
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
Built Distribution
Hashes for snakestream-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4732daefd042a94d6ae656d03e2b9f55188a14e1ac1f4e86718da12371da889 |
|
MD5 | 8795b37350dce2d9851cf169a92445ce |
|
BLAKE2b-256 | 76bd2f3fe9772d60f32f6cfdc5952a5a98711332c840c49303ec04742148c889 |