Alonzo Church

Image Credit: Wikipedia

Lambda Calculus

  • Introduced in 1930
  • Used to describe computation
  • Can be executed by any Turing machine
  • Built around mathematical functions

Programming Paradigms

Functions as First-Class Citizens

can store in variables
and use as arguments

Higher Order Functions

accept other functions as input

Imperative

const numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let result = 0;
for (let i = 0; i < numList.length; i++) {
    if (numList[i] % 2 === 0) {
        result += numList[i] * 10;
    }
}

result = 20 -> 60 -> 120 -> 200 -> 300

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

[2, 4, 6, 8, 10]

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

[20, 40, 60, 80, 100]

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

[60, 140, 100]

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

[200, 100]

Functional

const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        .filter(n => n % 2 === 0)
        .map(a => a * 10)
        .reduce((a, b) => a + b);

300