Anyone have examples where fold leads to easier to read code than a for loop in Rust?
I find it slightly difficult to read when the accumulator variable actually has multiple parts, like a complicated tuple. It's worse when part of the accumulator is a bool indicating whether it's finished; that's just a poor emulation of "break" in a for loop.
let string = "ewfsan";
let bitset = string.bytes().fold(0u32 |acc, ch| acc | 1 << (ch - b'a'));
This is a idiom that I have used many times so this being more consice than a for loop is a plusOf course if you have never seen a syntax before it will make less sense that anything you have seen before
The other direction is more interesting to me: Those are the awkward cases where people sometimes overdo it with the functional iterator heavy style.