-
Notifications
You must be signed in to change notification settings - Fork 314
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 product_ok
and sum_ok
#814
base: master
Are you sure you want to change the base?
Conversation
We have a bunch of methods about iterators of results: I think Now, do we want to add those shortcuts? That's the question. @jswrenn What do you think? EDIT: The documentation of sum (same for product) mention panics. It would do the same here.
I failed to read the documentation once but if this is not mentioned then someone will have a problem. |
Done! |
`.try_product()` is a more convenient way of writing `.product::<Result<_, _>>()` `.try_sum()` is a more convenient way of writing `.sum::<Result<_, _>>()`
Done! |
/// Ok(()) | ||
/// } | ||
/// ``` | ||
fn product_ok<T, U, E>(self) -> Result<U, E> |
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.
Hm, this is an inelegantly large number of generic arguments.
This is a fairly radical alternative, but: What if we just mirrored the stdlib Try
trait? We can pub-in-priv our Try
-fork so that folks don't end up explicitly depending on it, and then simply (and potentially non-breaking-ly!) switch over to the standard library Try
once it's stabilized.
If we do this, our *_ok
functions will support more than just Result
s, and they'll be able to take just one generic argument, rather than three (I think).
Thoughts, @Philippe-Cholet and @phimuemue?
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.
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.
That sure is radical but interesting, maybe it should have its own issue.
About the names, *_ok
now and try_*
later? (or maybe_*
?!)
After a quick look, ControlFlow
requires 1.55+ while we currently have 1.43. Unless we copy it too?
I previously read something about #[track_caller]
but don't remember much about its use.
In libcore, fold
is usually specialized using try_fold
specializations alongside with NeverShortCircuit
which surely won't be public forever so I thought that we would copy it at some point.
.try_product()
is a more convenient way of writing.product::<Result<_, _>>()
.try_sum()
is a more convenient way of writing.sum::<Result<_, _>>()
Modelled after
.try_collect()