stream-more

Crates.iostream-more
lib.rsstream-more
version0.1.3
sourcesrc
created_at2023-08-19 01:50:50.775178
updated_at2023-08-25 10:00:40.186945
descriptionStream utilities for Rust
homepagehttps://github.com/drmingdrmer/stream-more
repositoryhttps://github.com/drmingdrmer/stream-more
max_upload_size
id948449
size30,618
张炎泼 (drmingdrmer)

documentation

https://docs.rs/stream-more

README

stream-more

More utils to operate Stream in rust

StreamMore

StreamMore extends the functionality of Streams, providing additional methods for merging and sorting.

Features

  • kmerge_by: creates a k-way merge Stream by merging the given Streams according to a provided closure function.

  • kmerge_max: merges Streams by choosing the "greatest" item.

  • kmerge_min: merges Streams by choosing the "smallest" item.

Examples

Here are some examples of how to use the functions provided by StreamMore.

Merge streams in customized order:

use futures::StreamExt;
use futures::executor::block_on;
use futures::stream::iter;
use stream_more::StreamMore;

let x = iter([1, 3]);
let y = iter([2, 4]);

let m = x.kmerge_by(|a,b| a < b)
         .merge(y);

let got = block_on(m.collect::<Vec<u64>>());
assert_eq!(vec![1, 2, 3, 4], got);

Merge and choose smallest item:

let x = iter([3, 2]);
let y = iter([4, 1]);
let z = iter([5]);

let m = x.kmerge_min()
         .merge(y)
         .merge(z);

let got = block_on(m.collect::<Vec<u64>>());
assert_eq!(vec![1, 2, 3, 4, 5], got);
Commit count: 6

cargo fmt