Xah Talk Show 2019-09-08 functional programing explained with JavaScript. composition, closure, currying, etc
topics covered:
- explain functional programing in JavaScript
- JavaScript is based on scheme lisp and a language called Self.
- Douglas Crockford, who invented JSON and wrote JavaScript the Good Parts. He popularized functional programing in JavaScript in 2008
- JS: Functional Programing
- JS: Arrow Function
- if you like functional programing, then, in JavaScript, ALWAYS use arrow function. Never with keyword “function” or “class”. Never OOP.
- function taking function as argument
- function return a function
- example of function composition
- Currying is decomposing function that has multiple parameter, into a sequence of functions each with only 1 parameter.
- example of currying. What is Currying in Computer Science?
- example of closure. What is Closure in Programing Language
- closure and clojure.
- real world most common example of function taking a function, is in map and forEach.
// currying in JavaScript // this is a function that takes 2 args const ff = ((x,y) => x+y); console.log ( ff(3,4) === 7 ); const f1 = ((f) => ((y) => f(y))); const f2 = ((x) => ((y) => y+x) ); let x = 3; let y = 9917; console.log ( f1(f2(x))(y) === ff(x,y) );