by okasaki · 11y ago · 0 comments
int sum = 0;
for(auto&& wc : word_count) sum += wc.second
return sum;
It's shorter, more general, more familiar, possibly has better performance[[citation needed]], and gives better errors if you mess something up.Or at least it would in an ecosystem where functional programming is embraced, but I don't know how practical it is in practice. Its not composable if you can't expect any other given piece of code to be written in a way conducive to composing with accumulate.
In other languages, though, it's pretty neat. For example, in Rust one just does
data.iter().fold(0, |s, e| s + e)