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

Using tee

The first solution we'll use implies adding a function to the pipeline, which will just log its input. We want to implement something similar to the tee Linux command, which can intercept the standard data flow in a pipeline and send a copy to an alternate file or device. Remembering that /dev/tty is the usual console, we may execute something as follows and get an onscreen copy of everything that passes through the tee command:

$ ls -1 | grep "odt$" | tee /dev/tty | wc -l...the list of files with names ending in odt...4

We could write a similar function with ease:

const tee = arg => {    console.log(arg);    return arg;};
If you are aware of the uses of the comma operator, you can be quite more concise, and just write const tee = (arg) ...
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