order functions • takes one or more functions as an input (map, filter) • outputs a function (curry, any curried function) • map, filter, reduce, each etc… • pure functions • composition • currying • and more…
• Easy parallelization • More concise (DRY) - avoid spaghetti code • More reliable code • Easy to read (when in the FP mindset) • Easy to refactor (when in the FP mindset) • Easy to test
after the famous mathematician Haskell Curry) • Erlang (Ericsson Language) • Elm (works in the browser) • Scala (made popular by Twitter) • F# (Microsoft) • Javascript (has lots of FP properties, but not all)
programming • Vanilla js: Array.prototype.map, Array.prototype.filter… • JQuery: $.map, $.filter, $.each… • underscore: _.map, _.filter and many more • You’re used to work with functions, anonymous functions…
side effects -- it cannot modify the state of anything -- and it is referentially transparent -- when called multiple times with the same inputs, it always gives the same outputs.”
two = 2; function add2(x) { return x + two; }; //modifies its input, different results if called twice function pushIt(ar) { return ar.push('it') }; Impure functions example
curry(fn); fn('a','b','c') curriedFn('a','b','c') curriedFn('a','b')('c') curriedFn('a')('b')('c') // all these functions return ['a', 'b', 'c'] Currying example
pet library, not for production! • each, map, split, invoke, curry, and, or, propEq, dot, compose, reverse, split, join, where, match, groupBy, countBy, sum • All functions are curried (the collections are the last argument contrary to underscore)