Q:

ts generator

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
0

New to Communities?

Join the community