Message from JavaScript talks

May 2017

— Good example is a Promise itself

— 

A Promise is a specific type called a continuation monad, a type of a thunk used in continuation-passing style

— 

thunk is a function that encapsulates synchronous or asynchronous code inside.

thunk accepts only one callback function as an arguments, which is a CPS function.

thunk returns another thunk function after being called, for chaining operations.

thunk passes the results into a callback function after being excuted.

If the return value of callback is a thunk function, then it will be executed first and its result will be sent to another thunk for excution, or it will be sent to another new thunk function as the value of the computation.

Message permanent page

— I see

— Welcome

— 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.

Message permanent page

— For example, something like take n elements

— Aah

— So...

— In JS a generator is a thunk?

— Yep.