File: generators.md

package info (click to toggle)
coffeescript 2.7.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,360 kB
  • sloc: makefile: 20; xml: 9; sh: 6; javascript: 5
file content (17 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
## Generator Functions

CoffeeScript supports ES2015 [generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) through the `yield` keyword. There's no `function*(){}` nonsense — a generator in CoffeeScript is simply a function that yields.

```
codeFor('generators', 'ps.next().value')
```

`yield*` is called `yield from`, and `yield return` may be used if you need to force a generator that doesn’t yield.

<div id="generator-iteration" class="bookmark"></div>

You can iterate over a generator function using `for…from`.

```
codeFor('generator_iteration', 'getFibonacciNumbers(10)')
```