-
Notifications
You must be signed in to change notification settings - Fork 12
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 Iterator::try_collect #295
Comments
(on the bit I've been quoted for)
This doesn't resolve the conflict between iterating results1 and fallible collection, but it keeps consistency with the other Footnotes
|
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes chromium#295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
Closes #295 try_collect can collect from an iterator of `T: Try` into a container C that supports FromIterator<T: Try> to create C<U>. The actual Try types do not need to support FromIterator then, and this replaces the need for Option or Result to implement FromIterator. We needed to add another operation on Try types for this, which is to convert from T: Try in an error state to U: Try in an error state, where they have the same (or a convertible) error type. This new concept is sus::ops::TryErrorConvertibleTo and it's accessed through sus::ops::try_preserve_error(). The TryErrorConvertibleTo concept is implemented for Option, Result and std::optional.
rust-lang/rust#94047
The open questions there are:
No. That would defeat the primary purpose of making something more discoverable/accessible than
collect()
for results. If you need to do something more complicated you can use other tools for the job. Also consistency - the other try_ methods of iterators do not return partial results.No. Consistency with other try_ methods on iterators, and this makes it less useful. Fallible iteration is primarily useful to be able to terminate early for resuming after.
The name is consistent with try_fold etc, which makes it discoverable. It should follow the same pattern for a short-circuiting fallible collect with try_collect.
The text was updated successfully, but these errors were encountered: