Processing endless lists in CoffeeScript

In Haskell, I can do this to handle an infinite list.

takeWhile (<1000) [1 ..] 

Is there a way to do this in CoffeeScript?

+6
source share
2 answers

StreamJS allows you to create "endless" lists in javascript.

Using the (roughly) coffeescript port :

 # Stream.range() creates a list from 1...Infinity numbers = Stream.range().until (x) -> x > 1000 
+7
source

Not like built-in primitives, but they can be hacked, as in most other languages. At least someone plays CoffeeScript with him; see https://github.com/swannodette/fun.coffee/blob/master/src/fun.coffee . For solutions that look less “hacked,” you can read on CPS and maintain proper tail calls, see http://blog.mozilla.com/dherman/2011/01/30/proper-tail-calls-in-harmony / .

+3
source

Source: https://habr.com/ru/post/906782/


All Articles