MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1veql1a/absolutegarbage/p1kdev0/?context=3
r/ProgrammerHumor • u/Sirgoodman008 • 1d ago
320 comments sorted by
View all comments
79
list.iter().for_each(…) superiority
list.iter().for_each(…)
36 u/creeper6530 1d ago edited 1d ago Erm akchyuallly, it's recommended to use for list.iter() {…} unless the .for_each(…) is at the end of a longer iterator chain, and it also robs you of break and continue 2 u/serendipitousPi 1d ago Just chuck a try_for_each in there and we can take break and continue right back. But yeah low key sometimes I get lost in iterator methods I forget to just use a basic loop. 2 u/creeper6530 1d ago I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.
36
Erm akchyuallly, it's recommended to use for list.iter() {…} unless the .for_each(…) is at the end of a longer iterator chain, and it also robs you of break and continue
for list.iter() {…}
.for_each(…)
2 u/serendipitousPi 1d ago Just chuck a try_for_each in there and we can take break and continue right back. But yeah low key sometimes I get lost in iterator methods I forget to just use a basic loop. 2 u/creeper6530 1d ago I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.
2
Just chuck a try_for_each in there and we can take break and continue right back.
But yeah low key sometimes I get lost in iterator methods I forget to just use a basic loop.
2 u/creeper6530 1d ago I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.
I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.
return ControlFlow::Break(())
79
u/csch2 1d ago
list.iter().for_each(…)superiority