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

Unary operators

In the Logically negating a function section of Chapter 6, Producing Functions – Higher-Order Functions, we wrote a not() function that, given another function, would logically invert its result. We used that function to negate a check for negative balances; the sample code for this could be as follows:

const not = fn => (...args) => !fn(...args);const positiveBalance = not(isNegativeBalance);

In another section of that very same chapter, Turning operations into functions, I left you with the challenge of writing a unaryOp() function that would provide unary functions equivalent to common JavaScript operators. If you met that challenge, you should be able to write something like the following:

const logicalNot = unaryOp("!") ...
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