-
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
Consider adding a foreach-like iterator adapter #1070
Comments
Alternatively, there could just be a method to drain the iterator so you wouldn't have to use |
Are there any situations where you wouldn't want to use a for-loop? |
It looks much worse when you're working with a chain of iterators. |
I can think of two use cases where it might be convenient more convenient than a
for x in values {
my_log(x)
}
values.foreach(my_log)
|
See here for reasoning (which I agree with) why the equivalent method wasn't included in .NET's LINQ. |
|
Proposed in #582 and #1064, the
Iterator
trait could have a.foreach
method which drains the iterator immediately and runs a closure on each element to concisely do so without afor
loop.The text was updated successfully, but these errors were encountered: