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 ...
Get Programming Clojure, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.