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.
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?
2 comments
[ 5.3 ms ] story [ 12.2 ms ] threadBut 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?