-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a try_collect()
helper method to Iterator
#94041
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) soon. Please see the contribution instructions for more information. |
Updated the @rustbot label -S-waiting-on-author +S-waiting-on-review |
This comment has been minimized.
This comment has been minimized.
That CI failure makes no sense. I'll try closing and reopening. |
This comment has been minimized.
This comment has been minimized.
Tracking issue: #94047 |
619de21
to
30197c1
Compare
|
||
let u: Vec<Result<i32, ()>> = vec![Ok(1), Ok(2), Ok(3)]; | ||
let v = u.into_iter().try_collect::<Vec<i32>>(); | ||
assert_eq!(v, Ok(vec![1, 2, 3])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is already possible with .collect()
. Thanks to impl<A, E, V> FromIterator<Result<A, E>> for Result<V, E> where V: FromIterator<A>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but the main benefits of try_collect()
are increasing the discoverability of this technique and allowing Try
-but-not-FromIterator
types (e.g. ControlFlow
) to be fallibly collected as well. See my comment on the tracking issue here for a more thorough description of the differences between try_collect()
and collect()
.
Tweaked `try_collect()` to accept more `Try` types Updated feature attribute for tracking issue
The ICE in CI is caused by the use of intra-doc links involving I'm pretty sure you can just reference them without qualification (like You can test documentation with |
30197c1
to
47d5196
Compare
Oh, and @rustbot label -S-blocked |
Thank you, ehuss! And for the PR + updates, @a-lafrance! This looks good to go into unstable by me. Lots more discussion to be had on the tracking issue, to be sure. |
📌 Commit 47d5196 has been approved by |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#93337 (Update tracking issue numbers for inline assembly sub-features) - rust-lang#93758 (Improve comments about type folding/visiting.) - rust-lang#93780 (Generate list instead of div items in sidebar) - rust-lang#93976 (Add MAIN_SEPARATOR_STR) - rust-lang#94011 (Even more let_else adoptions) - rust-lang#94041 (Add a `try_collect()` helper method to `Iterator`) - rust-lang#94043 (Fix ICE when using Box<T, A> with pointer sized A) - rust-lang#94082 (Remove CFG_PLATFORM) - rust-lang#94085 (Clippy: Don't lint `needless_borrow` in method receiver positions) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Implement
Iterator::try_collect()
as a helper aroundIterator::collect()
as discussed here.First time contributor so definitely open to any feedback about my implementation! Specifically wondering if I should open a tracking issue for the unstable feature I introduced.
As the main participant in the internals discussion: r? @scottmcm