Message from JavaScript discussions

May 2017

— A nice example of a thunk is an infinite list.

— 

A computer obviously can't hold an infinitely long list, but if you encapsulate it such that you get the value only when it's needed, then you can perform operations on it.

— For example, something like take n elements

— Aah

— So...

— In JS a generator is a thunk?

— Yep.

— It suspends the execution context until a value is needed.

— I know

— The execution suspension in generators / async functions is so fucking good for keeping state

— No need to actually manage it yourself

— Yep.