January 2020
Intermediate to advanced
470 pages
11h 13m
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, while 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 the .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.) ...
Read now
Unlock full access