rust-itertools / itertools

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

Add `product_ok` and `sum_ok` #814

Open sjackman opened 10 months ago

sjackman commented 10 months ago

Modelled after .try_collect()

Philippe-Cholet commented 10 months ago

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.

sjackman commented 10 months ago

For consistency, I would suggest names to be product_ok and sum_ok.

Done!

sjackman commented 10 months ago

EDIT: The documentation of sum (same for product) mention panics. It would do the same here.

Done!

Philippe-Cholet commented 9 months ago

@jswrenn Merry Xmas. What do you think about adding product_ok and sum_ok? (There is also #830 about a fold_while_ok?)