I subscribe to a newsletter that has a coding challenge every week.
I did this week's in #Rust, but I'm sure there are many ways to make it more compact/better....
help welcome! How do I use map to sum over a Vector of structs?
@schlink You may need to use .fold() instead of .map()
@schlink i'd have used that:
let slices_needed: usize = persons.iter().map(|p| p.slices_requested).sum();
with map to get the number we need, and sum to concisely sum them.
fold could work too but i find it more verbose and less elegant
@schlink heeeeey, so you're back, learning things about Rust! Ping me anytime, and how's async going?
The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!