DEV Community

Discussion on: Stop Telling People For Loops Are Bad

Collapse
 
jessekphillips profile image
Jesse Phillips

Interesting as I responded to a similar inquiry.

forum.dlang.org/post/suinxiufqltip...

foreach(i; iota(10)
    .filter!(x => x%2)
    .until!(x => x>5)
    .map!"a * a"
    .filter!(x => x%4)) {
    i.writeln;
    break;
   }

But it was with a language where libraries are written with generic iteration. Yes arrays are used heavily but only stack allocation for this example, with early exits and multiple filtering.

But your context is Javascript, and context is important because as you point out it costs where functional languages can play tricks.

I just want to note that JS could be a better language if they'd just learn from others, and the community could get behind doing things better.