Skip to content

Commit b5815ea

Browse files
author
=
committed
generators add translation korean
1 parent 5c76597 commit b5815ea

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

docs/generators.md

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
## Generators
22

3-
`function *` is the syntax used to create a *generator function*. Calling a generator function returns a *generator object*. The generator object just follows the [iterator][iterator] interface (i.e. the `next`, `return` and `throw` functions).
3+
*제네레이터 함수*의 문법은 `function *`으로 작성합니다. 제네레이터 함수는 호출중에 제네레이터 객체를 리턴합니다. 제네레이터 객체는 [iterator][iterator] 인터페이스를 따라갑니다. (예: `next`, `return`그리고 `throw`함수가 있습니다.)
44

5-
There are two key motivations behind generator functions:
5+
제네레이터 함수에는 두가지 주요동기가 있습니다.
66

77
### Lazy Iterators
88

9-
Generator functions can be used to create lazy iterators e.g. the following function returns an **infinite** list of integers on demand:
9+
제네레이터 함수를 이용하면 lazy iterators를 만드는데 사용할 수 있습니다. 예: 다음 함수는 필요에 따라 **infinite** 숫자 목록을 반환합니다.
1010

1111
```ts
1212
function* infiniteSequence() {
13-
var i = 0;
14-
while(true) {
15-
yield i++;
13+
var i = 0
14+
while (true) {
15+
yield i++
1616
}
1717
}
1818

19-
var iterator = infiniteSequence();
19+
var iterator = infiniteSequence()
2020
while (true) {
21-
console.log(iterator.next()); // { value: xxxx, done: false } forever and ever
21+
console.log(iterator.next()) // { value: xxxx, done: false } forever and ever
2222
}
2323
```
2424

25-
Of course if the iterator does end, you get the result of `{ done: true }` as demonstrated below:
25+
물론 iterator가 끝나면 `{ done: true }`의 결과를 얻습니다. 아래에 그 예가 있습니다.
2626

2727
```ts
28-
function* idMaker(){
29-
let index = 0;
30-
while(index < 3)
31-
yield index++;
28+
function* idMaker() {
29+
let index = 0
30+
while (index < 3) yield index++
3231
}
3332

34-
let gen = idMaker();
33+
let gen = idMaker()
3534

36-
console.log(gen.next()); // { value: 0, done: false }
37-
console.log(gen.next()); // { value: 1, done: false }
38-
console.log(gen.next()); // { value: 2, done: false }
39-
console.log(gen.next()); // { done: true }
35+
console.log(gen.next()) // { value: 0, done: false }
36+
console.log(gen.next()) // { value: 1, done: false }
37+
console.log(gen.next()) // { value: 2, done: false }
38+
console.log(gen.next()) // { done: true }
4039
```
4140

4241
### Externally Controlled Execution
43-
This is the part of generators that is truly exciting. It essentially allows a function to pause its execution and pass control (fate) of the remainder of the function execution to the caller.
4442

45-
A generator function does not execute when you call it. It just creates a generator object. Consider the following example along with a sample execution:
43+
일부 제네레이터 함수는 정말 흥미진진합니다. 기본적으로 함수가 실행을 일시중지하고 나머지 함수실행을 호출자에게 전달할 수 있습니다.
44+
45+
호출해도 제네레이터 함수가 실행되지 않습니다. 그것은 단지 제네레이터 객체를 생성합니다. 샘플 실행과 함께 다음 예제를 고려하십시요.
4646

4747
```ts
48-
function* generator(){
49-
console.log('Execution started');
50-
yield 0;
51-
console.log('Execution resumed');
52-
yield 1;
53-
console.log('Execution resumed');
48+
function* generator() {
49+
console.log('Execution started')
50+
yield 0
51+
console.log('Execution resumed')
52+
yield 1
53+
console.log('Execution resumed')
5454
}
5555

56-
var iterator = generator();
57-
console.log('Starting iteration'); // This will execute before anything in the generator function body executes
58-
console.log(iterator.next()); // { value: 0, done: false }
59-
console.log(iterator.next()); // { value: 1, done: false }
60-
console.log(iterator.next()); // { value: undefined, done: true }
56+
var iterator = generator()
57+
console.log('Starting iteration') // This will execute before anything in the generator function body executes
58+
console.log(iterator.next()) // { value: 0, done: false }
59+
console.log(iterator.next()) // { value: 1, done: false }
60+
console.log(iterator.next()) // { value: undefined, done: true }
6161
```
6262

63-
If you run this you get the following output:
63+
이것을 실행하면 다음과 같은 결과값을 얻을 수 있습니다.
6464

6565
```
6666
$ node outside.js
@@ -73,63 +73,63 @@ Execution resumed
7373
{ value: undefined, done: true }
7474
```
7575

76-
* The function only starts execution once `next` is called on the generator object.
77-
* The function *pauses* as soon as a `yield` statement is encountered.
78-
* The function *resumes* when `next` is called.
76+
- 제네레이터 함수를 시작하는 방법은 오직 `next`를 이용해서 호출할때 실행되며 이것은 제네레이터 객체에 해당됩니다.
77+
- 제네레이터 함수를 중지하는 방법은 `yield`를 이용해야 합니다.
78+
- 제레레이터 함수를 다시 시작하려면 `next`를 호출해야 합니다.
7979

80-
> So essentially the execution of the generator function is controllable by the generator object.
80+
> 본질적으로 제네레이터 함수의 실행은 제네레이터 객체에 의해 제어 가능합니다.
8181
82-
Our communication using the generator has been mostly one way with the generator returning values for the iterator. One extremely powerful feature of generators in JavaScript is that they allow two way communications (with caveats).
82+
제네레이터를 사용한 우리가 배웠던 방법은 대부분 이터레이터를 이용한 값을 반환하는 한가지 방법입니다. 자바스크립트의 제네레이터에는 하나의 매우 강력한 기능은 양방향 통신을 허용한다는 것입니다.
8383

84-
* you can control the resulting value of the `yield` expression using `iterator.next(valueToInject)`
85-
* you can throw an exception at the point of the `yield` expression using `iterator.throw(error)`
84+
- 당신은 `iterator.next(valueToInject)`를 이용해서 `yield` 표현식의 결과값을 제어 할 수 있습니다.
85+
- 당신은 `iterator.throw(error)`를 이용해서 `yield` 표현식의 시점에서 예외처리를 할 수 있습니다.
8686

87-
The following example demonstrates `iterator.next(valueToInject)`:
87+
`iterator.next(valueToInject)`를 예제에서 증명하고 있습니다.
8888

8989
```ts
9090
function* generator() {
91-
const bar = yield 'foo'; // bar may be *any* type
92-
console.log(bar); // bar!
91+
const bar = yield 'foo' // bar may be *any* type
92+
console.log(bar) // bar!
9393
}
9494

95-
const iterator = generator();
95+
const iterator = generator()
9696
// Start execution till we get first yield value
97-
const foo = iterator.next();
98-
console.log(foo.value); // foo
97+
const foo = iterator.next()
98+
console.log(foo.value) // foo
9999
// Resume execution injecting bar
100-
const nextThing = iterator.next('bar');
100+
const nextThing = iterator.next('bar')
101101
```
102102

103-
Since `yield` returns the parameter passed to the iterator's `next` function, and all iterators' `next` functions accept a parameter of any type, TypeScript will always assign the `any` type to the result of the `yield` operator (`bar` above).
103+
`yield`는 이터레이터의 `next`함수에 전달된 매개변수를 반환하기 때문에 그리고 모든 이터레이터는 `next`함수는 모든 유형의 매개변수를 허용하고, 타입스크립트는 `yield`연산자의 결과에 `any`타입을 할당합니다.
104104

105-
> You are on your own to coerce the result to the type you expect, and ensure that only values of that type are passed to next (such as by scaffolding an additional type-enforcement layer that calls `next` for you.) If strong typing is important to you, you may want to avoid two-way communication altogether, as well as packages that rely heavily on it (e.g., redux-saga).
105+
> 당신은 당신이 기대하는 타입으로 결과를 강요하려고 합니다. 그리고 그것은 오직 값만 전달하는지 확인하십시요. 만약 당신이 강력한 타이핑이 중요한 경우에는 양방향 바인딩을 피하고 패키지를 많이 사용하는 패키지를 피할 수 있습니다. (예: redux-saga)
106106
107-
The following example demonstrates `iterator.throw(error)`:
107+
`iterator.throw(error)`의 예제를 아래에서 증명합니다.
108108

109109
```ts
110110
function* generator() {
111111
try {
112-
yield 'foo';
113-
}
114-
catch(err) {
115-
console.log(err.message); // bar!
112+
yield 'foo'
113+
} catch (err) {
114+
console.log(err.message) // bar!
116115
}
117116
}
118117

119-
var iterator = generator();
118+
var iterator = generator()
120119
// Start execution till we get first yield value
121-
var foo = iterator.next();
122-
console.log(foo.value); // foo
120+
var foo = iterator.next()
121+
console.log(foo.value) // foo
123122
// Resume execution throwing an exception 'bar'
124-
var nextThing = iterator.throw(new Error('bar'));
123+
var nextThing = iterator.throw(new Error('bar'))
125124
```
126125

127-
So here is the summary:
128-
* `yield` allows a generator function to pause its communication and pass control to an external system
129-
* the external system can push a value into the generator function body
130-
* the external system can throw an exception into the generator function body
126+
여기에 설명이 있습니다.
127+
128+
- 제네레이터 함수는 `yield`를 통해 통신을 일시중지하고 외부 시스템에 제어를 전달할 수 있게 합니다.
129+
- 외부 시스템에서 값을 제네레이터 함수안으로 밀어넣을수 있습니다.
130+
- 외부 시스템에서 예외를 제네레이터 함수안으로 던질 수 있습니다.
131131

132-
How is this useful? Jump to the next section [**async/await**][async-await] and find out.
132+
이것은 어떻게 활용할 수 있나요? 다음장에서 [**async/await**][async-await]으로 이동하여 알아보십시요.
133133

134-
[iterator]:./iterators.md
135-
[async-await]:./async-await.md
134+
[iterator]: ./iterators.md
135+
[async-await]: ./async-await.md

0 commit comments

Comments
 (0)