Ad

Sometimes one has a vector with pairs (key, value), where one wants to fold over all the values with the same key.
What is the best way to do that in Rust?

The example uses a vector, but perhaps it would be better with an iterator as argument, to make it more general?

fn reduce<TK, TV, TS, F>(v : Vec<(TK, TV)>,
                     s : TS,
                     f : F) -> Vec<(TK, TV)>
                     where F : Fn(TS, TV) -> TS {
    // Code
    vec![]
}