let iter = something.map(|x| ..);
for x in iter {
do_something(x);
}
It's still okay to use Iterator::map and other iterator combinators, but using for instead of for_each here is probably easier to read.
[0] One exception is in the documentation "In some cases for_each may also be faster than a loop, because it will use internal iteration on adapters like Chain."
Yep! That's why Iterator::for_each https://doc.rust-lang.org/stable/std/iter/trait.Iterator.htm... is more often than not a code smell [0]; it exists mostly for the sake of writing side effects in functional style.
So something like
Should probably be written It's still okay to use Iterator::map and other iterator combinators, but using for instead of for_each here is probably easier to read.[0] One exception is in the documentation "In some cases for_each may also be faster than a loop, because it will use internal iteration on adapters like Chain."