3 releases

0.1.3 Aug 25, 2023
0.1.1 Aug 19, 2023
0.1.0 Aug 19, 2023

#666 in Algorithms

Download history 2858/week @ 2024-03-14 2854/week @ 2024-03-21 2812/week @ 2024-03-28 1595/week @ 2024-04-04 1837/week @ 2024-04-11 1965/week @ 2024-04-18 1983/week @ 2024-04-25 1506/week @ 2024-05-02 3369/week @ 2024-05-09 2431/week @ 2024-05-16 2100/week @ 2024-05-23 2201/week @ 2024-05-30 2020/week @ 2024-06-06 1479/week @ 2024-06-13 2357/week @ 2024-06-20 2051/week @ 2024-06-27

8,401 downloads per month

MIT/Apache

31KB
546 lines

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);

Dependencies

~1MB
~17K SLoC