In Javascript
In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data
"Talk is cheap , show me the code"
Sum of Array
var arr = {1,2,3}
arr[4] = 4;
//Imperative Style
var sum = 0;
for(var i =0;i<arr.length;i++){
sum = sum + arr[i]
}
console.log(sum); //NaN
//Functional Style
//Abstract out the addition
console.log(arr.reduce(sum) ); //10
_.reduce
The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) has to reduce it to a single value.
_.reduce([1, 2, 3], function(acc, num){ return acc + num; }, 0)
Nicholas Zakas
var Line = server.getLine();
//pass that around
Line.inventory.revenue = 100;
var line = Line.init(server.getLine());
line.updateRevenue(1000);
Concept Of Thunks , Chaining and PipeLining
Line.calculateDiscount(10).calculateInventoryRevenue().calculateExpectedPrice().value();
Function PipeLining
(The thrush Combinator)
In object-oriented programming languages, a mixin is a class that contains a combination of methods from other classes. How such a combination is done depends on the language, but it is not by inheritance.
Mixins
Some Libraries
- Abhik