Skip to main content

Posts

Featured

Use JavaScript Generator To Kill Night King

So you know who killed Night King in Westeros. Only Valyrian steel can kill him, and Javascript can only kill mortals like you and me. In our JS land, Night King is a function who interacts with a generator function to illustrate a useful use case for generators in JavaScript. Don't whine about the spoiler if you are a fan and not watched yet. This is a lousy screenshot from Twitter Let's come back to the practical matter. I've thought about practical use case(s) for generator functions for a while, but couldn't find one that can't be implemented by pre-ES6 JS. For e.g., my first instinct was to build a factory for functions. The idea was to return a function based on the parameter passed to next() function. However, this show-off is unnecessary. This can be implemented directly using a function as below: Few folks suggested using it for asynchronous function call. However, async-await is readily available and crisp to use, so there's no need t

Latest Posts

Image

Pólya urn model

Howdy