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

Do not sum options #745

Closed Philippe-Cholet closed 1 year ago

Philippe-Cholet commented 1 year ago

A mistake on my part, discovered in time as code is still commented out. Note that it passed tests. It only returns None if the iterator yields None. But it would overflow whenever an addition does.

Do not product options either, as multiplications could overflow the same way. That's how I found out.

I guess checked_sum and checked_product methods would be nice. EDIT: ~Would you be interested?~ Related: https://github.com/rust-lang/rust/pull/95485

phimuemue commented 1 year ago

Nicely spotted @Philippe-Cholet.

Possibly indicates that we should really include the overflowing parts in tests.

bors r+

bors[bot] commented 1 year ago

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here. For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

Philippe-Cholet commented 1 year ago

I missed the "Panics" section of the sum method. So that's more embarassing than nicely spotted.