{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4306","repository_url":"https://api.github.com/repos/jashkenas/coffeescript","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4306/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4306/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4306/events","html_url":"https://github.com/jashkenas/coffeescript/pull/4306","id":176277330,"number":4306,"title":"Add a `for .. from ..` loop for generators, see #3832","user":{"login":"atg","id":32292,"avatar_url":"https://avatars.githubusercontent.com/u/32292?v=3","gravatar_id":"","url":"https://api.github.com/users/atg","html_url":"https://github.com/atg","followers_url":"https://api.github.com/users/atg/followers","following_url":"https://api.github.com/users/atg/following{/other_user}","gists_url":"https://api.github.com/users/atg/gists{/gist_id}","starred_url":"https://api.github.com/users/atg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atg/subscriptions","organizations_url":"https://api.github.com/users/atg/orgs","repos_url":"https://api.github.com/users/atg/repos","events_url":"https://api.github.com/users/atg/events{/privacy}","received_events_url":"https://api.github.com/users/atg/received_events","type":"User","site_admin":false},"labels":[{"id":18988,"url":"https://api.github.com/repos/jashkenas/coffeescript/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-09-12T01:19:08Z","updated_at":"2016-11-01T19:49:52Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jashkenas/coffeescript/pulls/4306","html_url":"https://github.com/jashkenas/coffeescript/pull/4306","diff_url":"https://github.com/jashkenas/coffeescript/pull/4306.diff","patch_url":"https://github.com/jashkenas/coffeescript/pull/4306.patch"},"body":"This implements a `for x from g` loop as argued for in [this comment](https://github.com/jashkenas/coffeescript/issues/3832#issuecomment-203739975).\n\nCurrently CoffeeScript supports generators using `yield` and `yield from`, but it doesn't support a way to _use_ these generators like `for (x of g)` in ES6.\n\nCoffeeScript already has `for in` (for Arrays) and `for of` (for Objects), however users expect both to generate es5-compatible code. It's impossible to modify either of these syntaxes to have all three of es5 compatibility, efficiency and support for generators/iterables.\n\nThat means the choice is either a compile-time flag or a new loop syntax. A compile-time flag is likely to create subtle bugs: if the code is expected to be compiled in es6 mode but is actually compiled in es5 mode, then a `for in` loop over an iterator will be a normal for loop `for (var i = 0; i < iterator.length; i++)`. Iterators are objects, and `.length` on an iterator is usually 0. The loop will therefore silently fail to run, with no error message.\n\nThat leaves a new loop syntax.\n\nThe best argument for introducing a new for loop syntax for generators is that they are fundamentally different from either arrays or objects. Iterating over a generator _mutates_ that generator, the next time you iterate over it, it will be empty. Generators cannot be iterated over in reverse order (because they are not indexed). Generators can be infinite.\n\nSo aside from being the only option, a new syntax has the benefit of making it clear from the code which loops are meant for Arrays, and which loops are meant for generators (or any iterable).\n\nAs for the specific syntax, `for x from y` is a nice complement to `yield from y`.\n"},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/257674740","html_url":"https://github.com/jashkenas/coffeescript/pull/4306#issuecomment-257674740","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4306","id":257674740,"user":{"login":"atg","id":32292,"avatar_url":"https://avatars.githubusercontent.com/u/32292?v=3","gravatar_id":"","url":"https://api.github.com/users/atg","html_url":"https://github.com/atg","followers_url":"https://api.github.com/users/atg/followers","following_url":"https://api.github.com/users/atg/following{/other_user}","gists_url":"https://api.github.com/users/atg/gists{/gist_id}","starred_url":"https://api.github.com/users/atg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atg/subscriptions","organizations_url":"https://api.github.com/users/atg/orgs","repos_url":"https://api.github.com/users/atg/repos","events_url":"https://api.github.com/users/atg/events{/privacy}","received_events_url":"https://api.github.com/users/atg/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T19:49:52Z","updated_at":"2016-11-01T19:49:52Z","body":"Alright, do it or don't. I got places to be."}}
{"actor":{"display_login":"atg"}}