Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

generator typescript

Generators:
1) They only compute the next value when the user asks for it.(pause the 
    execution after every output) 
2) They can generate infinte values.
3) Calling a generator return in iterable iterator.

//example
function* fibonacci(){
  let a = 0;
  let b = 1;
  while(true){
    yield a ;
    [a, b] = [b, a+b] ;
  }
};
let f = fibonacci();
f().next()   // give 0
f().next()   // give 1
 
PREVIOUS NEXT
Tagged: #generator #typescript
ADD COMMENT
Topic
Name
2+2 =