Add CheckedSum and CheckedProduct traits#251
Add CheckedSum and CheckedProduct traits#251wainwrightmark wants to merge 2 commits intorust-num:masterfrom
CheckedSum and CheckedProduct traits#251Conversation
cuviper
left a comment
There was a problem hiding this comment.
Rather than a new iter module here, I think it would make more sense to move this to the num-iter crate.
src/iter/checked_product.rs
Outdated
| /// Multiplies up an empty iterator returns a value representing One. | ||
| /// | ||
| /// If the iterator contains Zero, the order of elements may effect whether the result is `None`. | ||
| fn checked_product<I: Iterator<Item = Self>>(iter: I) -> Option<Result>; |
There was a problem hiding this comment.
This is opposite of how Product is defined, where the type parameter is the input (Item) and it always outputs Self. I would rather match that for consistency, and same for Sum.
There was a problem hiding this comment.
I completely agree. I feel very silly for having done it the other way around. I have changed it now.
src/iter/checked_product.rs
Outdated
| /// Multiplies up an empty iterator returns a value representing One. | ||
| /// | ||
| /// If the iterator contains Zero, the order of elements may effect whether the result is `None`. | ||
| fn checked_product(self) -> Option<Result>; |
There was a problem hiding this comment.
Similarly, for consistency with Iterator, this trait should have no parameters, and the method should be parameterized checked_product<P: CheckedProduct<Self::Item>>.
I think then we could also combine your two iterator extensions into one CheckedIterator trait, or even NumIterator to leave room for more extension methods.
There was a problem hiding this comment.
Another great idea, thankyou. I have done this and put both into NumIter
There was a problem hiding this comment.
Rather than a new
itermodule here, I think it would make more sense to move this to thenum-itercrate.
I wasn't sure. I'm very happy to close this pull request and move the code changes over there if that's best.
…um traits. Added NumIter and a blanket implementation
Closes #250
This adds
CheckedSumandCheckedProducttraits as well as blanket implementations for them.It also adds
CheckedSumIterandCheckedProductItertraits and blanket implementations for those as that provides a much more ergonomic interface, allowing you to do: