Skip to content

Add Itertools::{sum1, product1} #300

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

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

Emerentius
Copy link
Contributor

This implements sum1 and product1 consumers that are like sum and product except they produce an Option<T> with Some for nonempty iters and None otherwise, just like fold1.
That allows one to distinguish between an empty iter and iters that sum/multiply to their neutral element.

@Emerentius
Copy link
Contributor Author

error: expected one of ) or ,, found 4
--> /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.43/src/unix/mod.rs:107:46
|
107 | #[cfg_attr(feature = "align", repr(align(4)))]

Uh, I don't know what travis is complaining about

@jswrenn
Copy link
Member

jswrenn commented Sep 30, 2019

Thanks for the contribution! Could you rebase this on master?

Like fold1, these return Option<T>
Some(result) if the iter is nonempty, None otherwise.

Allows differentiation between empty iterators
and iterators that reduce to neutral elements
@Emerentius
Copy link
Contributor Author

Rebased and reworded the first line of the doc comments for both methods as commands Iterate over all … instead of statements Iterates over all … for consistency with other methods.

@jswrenn
Copy link
Member

jswrenn commented Oct 1, 2019

bors r+

bors bot added a commit that referenced this pull request Oct 1, 2019
300: Add Itertools::{sum1, product1} r=jswrenn a=Emerentius

This implements `sum1` and `product1` consumers that are like `sum` and `product` except they produce an `Option<T>` with `Some` for nonempty iters and `None` otherwise, just like `fold1`.
That allows one to distinguish between an empty iter and iters that sum/multiply to their neutral element.

Co-authored-by: Emerentius <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 1, 2019

Build succeeded

@bors bors bot merged commit 142659f into rust-itertools:master Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants