Functional Programming Concepts
Functional programming leads to code that is easier to write, read, test, and reuse. Here’s how it works.
Pure Functions
Programs are built out of pure functions. A pure function has no side effects; that is, it does not depend on anything but its arguments, and its only influence on the outside world is through its return value.
Mathematical functions are pure functions. Two plus two is four, no matter where and when you ask. Also, asking doesn’t do anything other than return the answer.
Program output is decidedly impure. For example, when you println, you change the outside world by pushing data onto an output stream. Also, the results of println depend on state outside the function: the standard output ...
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.
Read now
Unlock full access