begin in ES6

In order to write a begin lookalike in ES6, we can take advantage of the fact that in JavaScript arguments are evaluated from left to right. This leads to: const begin = (...args) => args[args.length - 1]; We can therefore replicate SICP's make-withdraw procedure as: const makeWithdraw = bal =>…

Pairs

let cons = (a, b) => (pick) => pick == 1 ? a : pick == 2 ? b : "error"; let car = (x) => x(1); let cdr = (x) => x(2); What if we could build pairs out of nothing at all?…

`yield` vs `yield*` in Koa.js

Although Koa.js does not advocate the use of yield*, it is good there is an article explaining the difference among the two.…

Promises and Generators: control flow utopia

Forbes Lindesay talks about how ES6 generators can help you make your asynchronous code easier to understand in terms of synchronous concepts. He discusses the alternative values you can use to represent a future and how they are all ultimately promises. Slides here.…