Functional Monthly 9
Details
Peter de Croos
Functional JS with Generators
Functional programing is oriented around abstractions built on functions. Generators are a new feature in ecmascript 6 for managing concurrency issues. Interestingly enough, generators are first class in much the same way functions are in javascript. I have found, through experimentation, ways to compose generators using functional ideas. In this lecture, I'll introuce the use of co for contructing lightweight coroutines using generators. One major limitation of co is that it operates on only one function. We'll continue with methods for composing one or more generators together into a single generator that can be dropped into a co() function or used as koa middleware. Once I've covered the basics, I'll cover the use of Shen, a library I built to abstract the messy details of generator composition so that you ca build entiire asynchronous control flows out of smaller generators. FInally, I'll give a lightweight introduction to koa and how to use shen and koa to build a basic todo app.