I think generators are a really good opportunity to: 1. Work at a higher-level of abstraction with normal for-loops and without producing functional programming spaghetti which others must work out. 2. Reduce the memory footprint of your code.
A recent programming idea I had: We can use generator functions to treat flat arrays as if they have structure instead of writing complicated nested loops or creating transforms which create intermediate structures. https://gist.github.com/sebinsua/67416ae6f7ca4051d3a7dc924f83d806 …pic.twitter.com/KJrIwsDSHr
-
-
Show this thread
-
More playing around with `AsyncIterable`s. Here's a higher-ordered function which can wrap any kind of iterable (including asynchronous iterables) to make JavaScript wait between each item. https://gist.github.com/sebinsua/c171d7ce7e9511b38d962e89ed17ebb6 …pic.twitter.com/P7xYyaWzrx
Show this thread -
OK - one annoying thing: you can create an infinite generator, but it can't be reused once it has completed (https://stackoverflow.com/a/23848531 ), and unfortunately it appears to move into the completed `[[GeneratorState]]` if you do things like `break` from a loop.
Show this thread -
(This doesn't seem to be the case, if you manually iterate within a `while` loop.)
Show this thread
End of conversation
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.