Y
Hacker News
new
|
ask
|
show
|
jobs
by
Gaelan
2410 days ago
Is Rust mainstream? If so, this code:
numbers.iter().map(|n| { ... }).sum();
Compiles to a plain loop, with no allocation.
1 comments
steveklabnik
2410 days ago
(You want for_each not map, by the way)
link
Gaelan
2410 days ago
Wait, why? AFIAK for_each doesn't return another iterator, and I'm calling sum afterward.
link
steveklabnik
2409 days ago
.... hacker news cut off the “sum” part, and so I didn’t see it. On my phone it just happened to clip it exactly long enough that it was still valid syntax, wow. Anyway, sorry and my bad!
link