Hacker News new | past | comments | ask | show | jobs | submit login

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.




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.


I find I frequently use a combination - use map/filter to setup an iterator, and then reduce it in a loop.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: