It's aΛ Thing

Underscore and Lodash

• A gentle introduction to functional ideas
• An object-oriented approach to these ideas
• Not built for a strong functional programming style
```                            ```
var myDataSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
evens,
odds;

evens = _(myDataSet)
.filter(function(value){
return value % 2 === 0;
})

odds = _(myDataSet)
.filter(function(value){
return value % 2 === 1;
})
```
```

This needs some help!

• Arguments in the wrong order
• Partial application
• Predicates
• Function composition
```                            ```
var myDataSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

filterEvens = j.partial(j.filter, j.isEven),
filterOdds = j.partial(j.filter, j.compose(j.not, j.isEven)),

evens = filterEvens(myDataSet),
odds = filterOdds(myDataSet);
```
```

We can do better.

This is a cute way to introduce some fun toys, but we can make this better. Let's simplify.

```                        ```
var myDataSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

evens = j.filter(j.isEven, myDataSet),
odds = j.filter(j.isOdd, myDataSet);
```
```

What do you get?

Referential transparency

```                            ```
var myArray = [1, 2, 3];

for(var i = 0; i < myArray.length; i++){
myArray[i] = myArray[i] * 3;
}
```
```
Versus
```                            ```
var multiplyBy3 = j.partial(j.multiply, 3),
myArray = j.map(multiplyBy3, [1, 2, 3]);
```
```

```                            ```
var finalValue = (passedValue !== undefined && passedValue !== null) ?
defaultValue : transformation(sanitizedValue);
```
```
Versus
```                            ```
var sanitizedValue = j.maybe(defaultValue, transformation, passedValue);
```
```

Stateless Interactions

```                            ```
//Stateful data management
myObj.prototype = {
processObj: function(tempObj){
this.finalObj.keyname = tempObj.keyName;
}
};
```
```
Versus
```                            ```
//Stateless data management
function processObj(tempObj){
j.pluck('keyName', tempObj);
}
```
```

References on Functional Programming

Books

• Functional Javascript -- Michael Fogus
• Land of Lisp -- Conrad Barski
• Learn You A Haskell for Great Good! -- Miran Lipovaca
• An Introduction to Functional Programming Through Lambda Calculus -- Greg Michaelson