Mark Lewis
May 29, 2021

--

Thanks for the post. I tend to prefer functional programming and I love seeing how nicely it can be done in Rust. I will note that in some languages, reduce and fold are similar, but slightly different operations. I spend most of my time in Scala where reduce does the first operation on the first two elements while fold take in a "zero" and does the first operation on that zero and the first element. This gives fold the ability to not only have a zero, but also to have a different result type than the type of the collection. Reduce lacks that flexibility, but is shorter to write when the flexibility isn't needed.

--

--

Mark Lewis
Mark Lewis

Written by Mark Lewis

Computer Science Professor, Planetary Rings Simulator, Scala Zealot

Responses (1)