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

Building pipelines by hand

Let's go with a Node.js example, similar to the command-line pipeline we built earlier in this chapter. We need a function to read all files in a directory and we can do that (in a not very recommendable way, because of the synchronous call, normally not good in a server environment) with something like this:

function getDir(path) {    const fs = require("fs");    const files = fs.readdirSync(path);    return files;}

Filtering the odt files is quite simple. We start with the following function:

const filterByText = (text, arr) => arr.filter(v => v.endsWith(text));

So, we can now write the following:

const filterOdt = arr => filterByText(".odt", arr);

Better still, we can applying currying, and go for pointfree style, as ...

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