I'm working on a pet project and I've found myself with a HashSet of tuples. Specifically
HashSet<(String,generic_array::GenericArray<u8,generic_array::typenum::U32>, u64)>
I'd like to sum the u64 element and can do so with a for loop without issue:
for element in hashset{
sum = sum+element.2;
}
However, I've come across the fold function for sets and I've written:
let y = hashset.fold(0, |sum x| sum+x)
Which works, but I'm unclear on the syntax of the |sum x|
. I can infer that I'm simply naming variables, but I don't understand how I would expand on this. Also how does fold know which element of the tuple to operate on?