DEV Community

Discussion on: Typewriter effect with vanilla async generators functions

Collapse
 
lionelrowe profile image
lionel-rowe

Nice demo! Note that strings are already iterable, so you can simplify spell like this:

async function* spell({ sentence, slowness = 75 }) {
  for (const char of sentence) {
    await delay(slowness);
    yield char;
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
eatsjobs profile image
Pasquale Mangialavori

True! It actually implements Symbol.iterator. thanks for pointing it out. :)