

A Bit of Functional Programming in Rust - charlieflowers
http://andreiformiga.com/blog/?p=382

======
charlieflowers
I would like to see more elaboration on _why_ things like fold are not
idiomatic Rust. The article mostly just states it without elaboration. If
anyone can elaborate, please do.

~~~
charlieflowers
Here's my initial guess as someone just beginning to learn the language.
Imagine you have a data structure that you need to work with, and many funcs
which operate on it. Striving for functional style, you'd prefer these funcs
not to mutate the data struct passed in to them. Rather, the funcs would
return a _new_ data struct that has the appropriate changes.

But that would generate a lot of "allocations" and "garbage." Possibly that
approach only makes sense in a language with a garbage collector. Presumably,
the main reason you would have chosen Rust in the first place is you desired
tight control over memory. Yet, this "pure function" approach which creates a
lot of garbage requires you to not care so much about tight control over
memory.

As I said, this is a guess -- where am I right and where am I wrong?

