-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 methods for cumulative folding and prefix sums #10789
Add methods for cumulative folding and prefix sums #10789
Conversation
This reverts commit d9ee24c.
@@ -44,6 +44,92 @@ describe Iterator do | |||
end | |||
end | |||
|
|||
describe "#accumulate" do |
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 think we can use the new Iterator spec helpers here
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.
But it can be done in a separate PR
# the collection. This initial value is always present in the returned array. | ||
# | ||
# ``` | ||
# [1, 3, 5, 7].accumulate(9) { |x, y| x * y } # => [9, 9, 27, 135, 945] |
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.
Can we use a different value than 1 here? It might make the behavior easier to understand
Closes #8496.
The interfaces (
Enumerable#accumulate
,Iterator#accumulate
,Iterable#each_accumulated
) are based on #8496 (comment), i.e. block-less overloads are used for prefix sums. All overloads are O(n).