4 ms·
Is Rust mainstream? If so, this code: numbers.iter().map(|n| { ... }).sum(); Compiles to a plain loop, with no allocation.
by Gaelan 7y ago
Is Rust mainstream? If so, this code:
numbers.iter().map(|n| { ... }).sum();
Compiles to a plain loop, with no allocation.
- steveklabnik 7y ago(You want for_each not map, by the way)
- Gaelan 7y agoWait, why? AFIAK for_each doesn't return another iterator, and I'm calling sum afterward.
- steveklabnik 7y 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!