itertools
itertools copied to clipboard
Add `product_ok` and `sum_ok`
.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()
We have a bunch of methods about iterators of results: map_ok filter_ok filter_map_ok flatten_ok fold_ok (and related but different process_results) and try_collect clashing with the nightly Iterator::try_collect.
I think try_ methods should be reserved to (unstable for now) Try trait usages.
For consistency, I would suggest names to be product_ok and sum_ok.
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.
Panics
When calling
sum()and a primitive integer type is being returned, this method will panic if the computation overflows and debug assertions are enabled.
I failed to read the documentation once but if this is not mentioned then someone will have a problem.
For consistency, I would suggest names to be
product_okandsum_ok.
Done!
@jswrenn Merry Xmas. What do you think about adding product_ok and sum_ok?
(There is also #830 about a fold_while_ok?)