Last active
March 20, 2021 12:38
-
-
Save ashwinkumar2438/87d8ef86064177dd51e24788b6daaa25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let childgen=function*(){ | |
yield 'child 1'; | |
yield 'child 2'; | |
return 'child 3'; | |
} | |
let parentgen=function*(){ | |
yield 'parent 1'; | |
yield 'parent 2'; | |
let lastchild=yield* childgen(); | |
return lastchild; | |
} | |
let ancestry=parentgen(); | |
console.log(ancestry.next()); //@yields {value: "parent 1", done: false} | |
console.log(ancestry.next()); //@yields {value: "parent 2", done: false} | |
console.log(ancestry.next()); //@yields {value: "child 1", done: false} | |
console.log(ancestry.next()); //@yields {value: "child 2", done: false} | |
console.log(ancestry.next()); //@returns {value: "child 3", done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment