3 ms·
Then replace the for loop with a parallel construct that's imperative. In terms of the language itself, map, reduce and filter are just sugar... different ways
by crimsonalucard 9y ago
Then replace the for loop with a parallel construct that's imperative. In terms of the language itself, map, reduce and filter are just sugar... different ways to loop through collections. Using one does not mean you are using FP, using immutability in java means that you are. That is the difference.
- steinuil 9y agoActually, for loops in languages like Ruby and OCaml are just syntactic sugar for map. Also, why would you prefer an imperative construct over different kinds of folds?
- crimsonalucard 9y agoI don't. My point is, it's all sugar, so in a sense it's the same thing when you're doing imperative programming. Whether you use a map or a for loop in your imperative code the structure of your program remains the same, the only difference is sugar... This is my point. Why are maps and folds so prevalent in functional programming? Because immutability and imperativeness render the concept of a for loop to be non-existent. Try to use a for loop with all const variables and no IO... your for loop will not be able to do any meaningful change to the state of your program.