JavaScript Currying 2 - Tacit programming Point-free style

September 11, 2020

Tacid programming (i.e., Point-free style) is a programming paradigm, where function definition does not refer to the function arguments. Function declaration, on the other hand, requires any formal parameters to be declared. Every point-free function has its closure scope. The closure is created at the function creation time - when the function is invoked. Every form of the curried function is a form fo higher-order-function

1const add = (a) => (b) => a + b
2const incrementByOne = add(1) // partially applied function
3incrementByOne(9) // => 10

When we create incrementByOne with function call add(1), the a parameter from add function get fixed to 1 inside the returned function that gets assigned to incrementByOne function. When we call incrementByOne function with b parameter fixed to 9 function application completes, and returns the sum of 1 and 9.

1// Another example of point-free style function
2const g = (n) => n + 1
3const f = (n) => n * 2
4const h = (x) => f(g(x))
5h(20) // => 42