JavaScript Scene
Published in

JavaScript Scene

The Rise and Fall and Rise of Functional Programming (Composing Software)

Smoke Art Cubes to Smoke — MattysFlicks — (CC BY 2.0)

The Rise of Functional Programming

  1. Functions are always anonymous. In JavaScript, the right side of const sum = (x, y) => x + y is the anonymous function expression (x, y) => x + y.
  2. Functions in lambda calculus only accept a single input. They’re unary. If you need more than one parameter, the function will take one input and return a new function that takes the next, and so on. The n-ary function (x, y) => x + y can be expressed as a unary function like: x => y => x + y. This transformation from an n-ary function to a unary function is known as currying.
  3. Functions are first-class, meaning that functions can be used as inputs to other functions, and functions can return functions.
f . g
compose2 = f => g => x => f(g(x))
double = n => n * 2
inc = n => n + 1
compose2(double)(inc)(3)
  1. The first passes double and returns a new function.
  2. The returned function takes inc and returns a new function.
  3. The next returned function takes 3 and evaluates f(g(x)), which is now double(inc(3)).
  4. x evaluates to 3 and gets passed into inc().
  5. inc(3) evaluates to 4.
  6. double(4) evaluates to 8.
  7. 8 gets returned from the function.
  1. Its simplicity makes it easy to learn the basic syntax and semantics of Lisp in about a day.
  2. Lisp is all about function composition, and function composition is an elegant way to structure applications.
  3. The best computer science text book I know of uses Lisp: Structure and Interpretation of Computer Programs.

The Fall of Functional Programming

The Rise of Functional Programming

Functional Programming Has Always Been Alive and Well

Learn More at EricElliottJS.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store