Skip to content
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

Product() of empty slice should be 1 (not 0). #583

Closed
your-diary opened this issue Jan 28, 2025 · 1 comment · Fixed by #584
Closed

Product() of empty slice should be 1 (not 0). #583

your-diary opened this issue Jan 28, 2025 · 1 comment · Fixed by #584

Comments

@your-diary
Copy link

PR #566 introduced Product() but I believe its return value for an empty slice is incorrect: it currently returns 0 but it should be 1.

Operations such as Sum() and Product() are so-called fold operations with the initial value mathematically called identity element. Normally, the identity element of product operation is 1, so Product(<empty slice>) should return 1 (not 0).

Supporting evidence:

@samber
Copy link
Owner

samber commented Jan 28, 2025

I agree. Thanks for the feedback.

I'm going to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants