coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

Add lazy comprehensions

Open FelipeSharkao opened this issue 4 years ago • 0 comments

Resolves #5379

Adds a syntax (I used for each, but is of course this is not defined) to allow comprehension to result in a generator instead of a array, similar to the python one.

nums    = (n * n for each n in [1, 2, 3] when n & 1)
results = (n * 2 for each n from nums)

results.next().value # 2
results.next().value # 18
results.next().done  # yes

FelipeSharkao avatar Oct 09 '21 23:10 FelipeSharkao