Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

An unnecessary mistake

There is, however, a common (though in fact, harmless) mistake that is usually made. You often see code like this:

fetch("some/remote/url").then(function(data) {  processResult(data);});

What does this code do? The idea is that a remote URL is fetched, and when the data arrives, a function is called—and this function itself calls processResult with data as an argument. That is to say, in the then() part, we want a function that, given data, calculates processResult(data). But don't we already have such a function?

A small bit of theory: in lambda calculus terms, we are replacing λx.func x with simply func—this is called an eta conversion, or more specifically, an eta reduction. (If you were to do it the other way round, ...
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

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content