rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.71k stars 309 forks source link

Feature request: `try_collect_vec()` #934

Open amab8901 opened 4 months ago

amab8901 commented 4 months ago

Same as try_collect() except that I don't have to specify Vec<_> as a type parameter

Philippe-Cholet commented 4 months ago

This might be done as part of #844. It might be named maybe_collect_vec and could be called on Iterator<Item = Option<T>> and on Iterator<Item = Result<T, E>> (and not just the second).

maybe_-prefixed to avoid any conflict with the stdlib which should own try_-prefixed methods. Our try_collect is in conflict with nightly Rust.

amab8901 commented 4 months ago

would be great to also have try_join() when the iterator has elements of type Result<String> or Result<&str>!

Philippe-Cholet commented 4 months ago

We probably won't add many maybe_/try_ methods.

But there is .process_results(|it| it.join()) that should work for your use case.