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

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 in order to negate a check for negative balances; sample code 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 the challenge of writing a unaryOp() function that would provide unary functions equivalent to common JS operators. So, if you are able to write the following:

const logicalNot = unaryOp("!");

Then, assuming the existence of a compose() function, ...

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