November 2017
Intermediate to advanced
386 pages
9h 22m
English
In Node, most asynchronous functions require a callback such as (err,data)=>{...}: if err is null, the function was successful, and data is its result, and if err has some value, the function failed, and err gives the cause. (See https://nodejs.org/api/errors.html#errors_node_js_style_callbacks for more on this.)
However, you might prefer to work with promises instead. So, we can think of writing a higher-order function that will transform a function that requires a callback into a promise that lets you use .then() and .catch() methods. (In Chapter 12, Building Better Containers - Functional Data Types, we will see that promises are actually monads, so this transformation is interesting in yet another way.) ...