News for hackers. Stuff that matters.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by nicoburns on Saturday December 31, 2022 @02:26PM (#34199776)
Functional iteration is good for the same reason we use for loops over while loops, and while loops over goto: they are more constrained, more clearly communicate intent, and are therefore easier to reason about.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by josephg on Saturday December 31, 2022 @03:22PM (#34200338)
Sure but it’s easy to go overboard with this stuff. Reduce (fold) especially can be pretty hard to read in hairy situations.

My general rule is that if you need fewer lines of code to implement your logic with a simple for loop, you probably should.

Re:Should Small Rust Structs be Passed by-copy or by-borrow? by nicoburns on Sunday January 01, 2023 @10:16AM (#34206911)
Yeah, I agree with that. Especially reduce/fold, which I find is almost always better written as loop. Filter would be a good example of the opposite for me: almost always much clearer written functionally.
Re:Should Small Rust Structs be Passed by-copy or by-borrow? by jamincan on Sunday January 01, 2023 @04:29PM (#34211153)
I find I frequently use a combination - use map/filter to setup an iterator, and then reduce it in a loop.