Skip to content

Implement itertools.accumulate #1372

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 3 commits into from
Sep 14, 2019

Conversation

j30ng
Copy link
Contributor

@j30ng j30ng commented Sep 13, 2019

#1361
This is an implementation of the Python standard library function itertools.accumulate. I also included a couple of very basic tests.

@j30ng j30ng force-pushed the itertools-accumulate branch from 11f19c3 to 708fd9b Compare September 13, 2019 16:16
Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; I've left a few comments. Thanks for contributing!

binop: binop.unwrap_or_else(|| vm.get_none()),
acc_value: RefCell::from(vm.get_none()),
}
.into_ref(vm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use into_ref_with_type() here and make the return type PyResult<PyItertoolsAccumulate>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for pointing out!

struct PyItertoolsAccumulate {
iterable: PyObjectRef,
binop: PyObjectRef,
acc_value: RefCell<PyObjectRef>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have this as an Option rather than using None as "not yet started iterating", because the binop function could return None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this wasn't carefully thought out.

Copy link
Contributor

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for me
Thanks @coolreader18

@coolreader18 coolreader18 merged commit fcd39a3 into RustPython:master Sep 14, 2019
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 this pull request may close these issues.

3 participants