November 2017
Intermediate to advanced
386 pages
9h 22m
English
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 ...