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

(You want for_each not map, by the way)
Wait, why? AFIAK for_each doesn't return another iterator, and I'm calling sum afterward.
.... 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!