Skip to content

foldl and foldr should pass the accumulator by value #4490

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

Closed
brson opened this issue Jan 15, 2013 · 1 comment
Closed

foldl and foldr should pass the accumulator by value #4490

brson opened this issue Jan 15, 2013 · 1 comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@brson
Copy link
Contributor

brson commented Jan 15, 2013

Right now they force each iteration to make copies.

@nikomatsakis
Copy link
Contributor

By the way, I think the only way to implement this safely is for
vectors, because they can use a while loop. For other code that uses a
generic each() method, I believe unsafe code is needed to manage the
moves. I have not come up with a simple way for the type system to prove
the absence of troublesome recursion (once fns are complex enough to
prove safe---and they don't address this problem). But I think the
interface should still be correct, as @brson says, even if it requires
an unsafe impl for the generic case.

bors added a commit that referenced this issue May 7, 2013
…, r=graydon

Closes #5311 and #4490.

This doesn't change `vec.foldl` because that's still part of `old_iter`, although I could change that as well if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

3 participants