Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmaxim committed Jun 4, 2024
1 parent 5740d94 commit 753a385
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ Either as a standalone stream operator or directly as a combinator.
```rust
use futures::{stream, StreamExt};
use min_batch::MinBatchExt;

#[derive(Debug, PartialEq, Eq)]
struct BlockOfTxs {
name: char,
txs_count: usize,
}

#[tokio::main]
async fn main() {
let mut block_names: Vec<char> = vec!['a', 'b', 'c', 'd'];
let min_match_size = 3;
let batches: Vec<Vec<BlockOfTxs>> = stream::iter(1..=4)
.map(|x| BlockOfTxs {
name: block_names[x - 1],
txs_count: x,
})
.min_batch(min_match_size, |block: &BlockOfTxs| block.txs_count)
.collect()
.await;
// Verify the batches
let batches: Vec<Vec<BlockOfTxs>> =
stream::iter(1..=4)
.map(|x| BlockOfTxs {
name: block_names[x - 1],
txs_count: x,
})
.min_batch(min_match_size, |block: &BlockOfTxs| block.txs_count)
.collect()
.await;

assert_eq!(batches.len(), 3);

// collect first two Blocks of Transactions until the total count of transactions is >= 3
Expand Down

0 comments on commit 753a385

Please sign in to comment.