stream-reduce 0.1.0

Fold a stream without an initial value
Documentation
  • Coverage
  • 50%
    2 out of 4 items documented1 out of 3 items with examples
  • Size
  • Source code size: 10.74 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 23s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • matthunz/stream-reduce
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • matthunz

This crate gives Streams a reduce function that is similar to fold but without an initial value. The function returns a Future containing None if the stream is empty and Some(value) otherwise.

Based on David Tolnay's reduce crate for iterators.

Examples

use stream_reduce::Reduce;
use futures::stream;

# futures::executor::block_on(
async {
    // Reduce a non-empty stream into Some(value)
    let v = vec![1usize, 2, 3, 4, 5];
    let sum = stream::iter(v).reduce(|a, b| async move { a + b }).await;
    assert_eq!(Some(15), sum);

    // Reduce an empty stream into None
    let v = Vec::<usize>::new();
    let product = stream::iter(v).reduce(|a, b| async move { a * b }).await;
    assert_eq!(None, product);
}
# )