What's the best use you've seen of a generator function in JavaScript? Where do they really shine?
-
-
There's overhead from using a generator but who cares. I don't know of another way to write this without having a lot of bookkeeping and manual callbacks.https://github.com/facebookexperimental/rome/blob/master/packages/%40romejs/core/master/fs/Resolver.ts#L437-L508 …
-
Mmm, very interesting. I do some module resolution on unpkg, but I know all the files in a package upfront, so the search is as easy as just doing e.g. `path || ${path}.js || ${path}/index.js`. Very different use case, but I immediately recognized what your code was doing
End of conversation
New conversation -
-
-
So you use the generator almost like a way of creating a list of lazily evaluated items, without the need for a function or method invocation? I'll have to remember this technique for future reference...
-
It's one of the most common use cases for generators, not just in JS but in other languages too.
End of conversation
New conversation -
-
-
@TChetwin used generators to solve the same problem! - 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 