jashkenas / jashkenas/coffeescript

Proposal: Lazy comprehensions

Open
#5,379 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

Create a syntax (I'm thinking in `for*`) for allowing comprehensions to produce an Iterator instead of a list, similar to what python does. This would help when the goal is not to map a list, but use the result in another iteration.

### Proposed Syntax

```coffeescript
somethingExpensive item for* item in list
```

### Normal Behavior

```js
(function() {
var i, len, results;
results = [];
for (i = 0, len = list.length; i < len; i++) {
item = list[i];
results.push(somethingExpensive(item));
}
return results;
})();
```

### Proposed Behavior

```js
(function*() {
var i, len;
for (i = 0, len = list.length; i < len; i++) {
item = list[i];
yield somethingExpensive(item);
}
return results;
})();
```

I'm planning on implementing that (as it does not seem hard, and you'd be a nice introduction to CoffeeScript architecture) so I wanted to know if it's a welcomed feature.

Contributor guide

Open the contributing guide

Research direction

The issue names no source files or tests. Start by reviewing the CoffeeScript compiler architecture and confirming the proposed for* syntax and iterator semantics with maintainers; done means an accepted implementation that produces iterators for lazy comprehensions without changing normal comprehension behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.