functions, select two with traits you’d like to combine and mash them together to spawn a brand new one.” Professor Frisby’s Mostly Adequate Guide to Functional Programming function compose(f, g) { return function (x) { return f(g(x)); }; }
[]; for (var i = 0; i < list.length; i++) { acc.push(f(list[i])); } return acc; } function negate(f) { return function (x) { return !f(x); }; } Functions that accept a function as an argument or return a function
Don’t need to account for side-effects when testing • Achieve full test coverage (unit & integration) • Declarative style reduces branches/permutations
classes • Long, complex render() methods • Used like a tempting engine • An example component: • 568 lines • onSubmit() and submitForm(); ~100 lines, ~20 if/else • ~50 lines of markup • Dozens of helpers that mutate variables