Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Turning functions into promises

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content