How to clone ES6 generator? [duplicate]
问题 This question already has answers here : Implementing monads in JavaScript (3 answers) Closed 5 months ago . I'm trying to create a List monad in ES6 using generators. To make it work I need to create a copy of an iterator that has already consumed several states. How do I clone an iterator in ES6? function* test() { yield 1; yield 2; yield 3; } var x = test(); console.log(x.next().value); // 1 var y = clone(x); console.log(x.next().value); // 2 console.log(y.next().value); // 2 (sic) I've