about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-06-30 09:15:21 +0000
committerbors <bors@rust-lang.org>2017-06-30 09:15:21 +0000
commit919c4a6707da3aa2cc9ff63e33057e1e2a90720b (patch)
tree632c6d954c24235be3944b55305654e4fd66ce8e /src/liballoc
parent4c5b437176a65c8686865bd7b8f9bb27c239d37c (diff)
parente72ee6e4ad0511aaf533a492382b84dfa712393f (diff)
downloadrust-919c4a6707da3aa2cc9ff63e33057e1e2a90720b.tar.gz
rust-919c4a6707da3aa2cc9ff63e33057e1e2a90720b.zip
Auto merge of #42782 - cuviper:iterator_for_each, r=alexcrichton
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
Diffstat (limited to 'src/liballoc')
0 files changed, 0 insertions, 0 deletions