rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.38k stars 622 forks source link

`StreamExt::scan` lacks a non-Option version #2860

Open sxlijin opened 4 months ago

sxlijin commented 4 months ago

My use case is this: given an incoming data stream, I want to provide a stream to the user consisting of the accumulated data stream, so ["lorem", "ipsum", "dolor"] would become ["lorem", "lorem ipsum", "lorem ipsum dolor"].

The currently implementation of StreamExt::scan makes this less ergonomic than is ideal, because I need to wrap everything in Some().

In addition, if I want the stream's entries to be Result<Foo>, and I want to unwrap the Err variant in one scan iteration, I can't use ? shorthand.

This feels a bit like scan should actually be named filter_scan, much like how map and filter_map are the non-Option and Option versions of each other.