-
Notifications
You must be signed in to change notification settings - Fork 130
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 CheckedSum
and CheckedProduct
traits
#251
base: master
Are you sure you want to change the base?
Conversation
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another great idea, thankyou. I have done this and put both into NumIter
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.
Rather than a new
iter
module here, I think it would make more sense to move this to thenum-iter
crate.
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
CheckedSum
andCheckedProduct
traits as well as blanket implementations for them.It also adds
CheckedSumIter
andCheckedProductIter
traits and blanket implementations for those as that provides a much more ergonomic interface, allowing you to do: