Skip to content

Add for_each_with #367

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
Jun 14, 2017
Merged

Add for_each_with #367

merged 1 commit into from
Jun 14, 2017

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Jun 14, 2017

I had considered this method when adding map_with and fold_with, but
at the time I decided it wasn't "primitive" enough. It is literally
just map_with(...).for_each(no-op). But we already have a user asking
the best way to drive a void map_with, so it may be useful to provide.

cc #365

I had considered this method when adding `map_with` and `fold_with`, but
at the time I decided it wasn't "primitive" enough.  It is literally
just `map_with(...).for_each(no-op)`.  But we already have a user asking
the best way to drive a void `map_with`, so it may be useful to provide.
@nikomatsakis
Copy link
Member

👍 I really wish we had for_each on seq iterators. Having to use a dummy operation is annoying.

@nikomatsakis nikomatsakis merged commit a4f105d into rayon-rs:master Jun 14, 2017
@cuviper
Copy link
Member Author

cuviper commented Jun 14, 2017

Regarding sequential iterators, I only found rust-lang/rust#14911, where the argument against seems mostly just that plain for loops are preferable. We'd need openmp-like support to do that with rayon.

cuviper referenced this pull request in cuviper/rust Jun 20, 2017
This works like a `for` loop in functional style, applying a closure to
every item in the `Iterator`.  It doesn't allow `break`/`continue` like
a `for` loop, nor any other control flow outside the closure, but it may
be a more legible style for tying up the end of a long iterator chain.

This was tried before in rust-lang#14911, but nobody made the case for using it
with longer iterators.  There was also `Iterator::advance` at that time
which was more capable than `for_each`, but that no longer exists.

The `itertools` crate has `Itertools::foreach` with the same behavior,
but thankfully the names won't collide.  The `rayon` crate also has a
`ParallelIterator::for_each` where simple `for` loops aren't possible.

> I really wish we had `for_each` on seq iterators. Having to use a
> dummy operation is annoying.  - [@nikomatsakis][1]

[1]: https://github.com/nikomatsakis/rayon/pull/367#issuecomment-308455185
bors referenced this pull request in rust-lang/rust Jun 30, 2017
Add `Iterator::for_each`

This works like a `for` loop in functional style, applying a closure to
every item in the `Iterator`.  It doesn't allow `break`/`continue` like
a `for` loop, nor any other control flow outside the closure, but it may
be a more legible style for tying up the end of a long iterator chain.

This was tried before in #14911, but nobody made the case for using it
with longer iterators.  There was also `Iterator::advance` at that time
which was more capable than `for_each`, but that no longer exists.

The `itertools` crate has `Itertools::foreach` with the same behavior,
but thankfully the names won't collide.  The `rayon` crate also has a
`ParallelIterator::for_each` where simple `for` loops aren't possible.

> I really wish we had `for_each` on seq iterators. Having to use a
> dummy operation is annoying.  - [@nikomatsakis][1]

[1]: https://github.com/nikomatsakis/rayon/pull/367#issuecomment-308455185
@cuviper cuviper deleted the for_each_with branch September 23, 2017 04:56
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.

2 participants