3 releases

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

#1415 in Algorithms

Download history 1877/week @ 2024-07-31 1795/week @ 2024-08-07 1819/week @ 2024-08-14 1225/week @ 2024-08-21 1194/week @ 2024-08-28 1448/week @ 2024-09-04 931/week @ 2024-09-11 1352/week @ 2024-09-18 994/week @ 2024-09-25 735/week @ 2024-10-02 1313/week @ 2024-10-09 1175/week @ 2024-10-16 1472/week @ 2024-10-23 1473/week @ 2024-10-30 1211/week @ 2024-11-06 1401/week @ 2024-11-13

5,759 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