What is the idiomatic way to write a map closure with a result type? Do I just collect it as a result and use a ? On it? Doesn’t that make the iteration occur twice? #rust #rustlang
0 reposts0 likes
What is the idiomatic way to write a map closure with a result type? Do I just collect it as a result and use a ? On it? Doesn’t that make the iteration occur twice? #rust #rustlang
0 reposts0 likes
I think you could replace starting at .collect() with .map(|result| result .map(/* your Ok value logic */)) .take_until(|result| result .is_err() .fold(|result| { let aggregate = result?/* rest of the fold logic here */ }) I use [take_until](docs.rs/take-until/l...), but take_while could work too