|
|
|
|
|
by throwaway097486
2014 days ago
|
|
A counter-counterpoint: classic for loops are hard to read and unpleasant to work with. They are so annoying, that the language designers extended the language/standard libraries to make them tolerable - array.map in ECMAScript 5, for (x : y) in Java 5 and C++11, foreach in PHP 4, LINQ extensions in C# 3. A plain old functor/monad has so much to recommend it. You get a uniform way to iterate/transform all kinds of collections, even those which don't support indexing. They can also be used without mutation and are easy to typecheck. In languages with higher-kinded types they can be abstracted over without knowing anything about how the underlying data is structured. |
|