finally, a slide deck that uses `history.replaceState` instead of `history.pushState`. no more having to hit "back" 90 times to exit the deck. how the latter ever became a pattern is beyond me.<p>[EDIT] it probably became a pattern because of browsers that didnt implement the history API, so all hashchange events were pushed onto the history stack.
For those you want to learn the functional programming I'd suggest to immedeately commence looking at Ocaml/Haskell instead to see the real big picture. Because it's of course adorable that you can write <i>map</i> and <i>compose</i> in JS (it's 2014, it can do it everywhere), but FP = many more serious things.
I'm a huge fan of lo-dash, but might switch to Ramda. Here's a rundown:<p><a href="http://bahmutov.calepin.co/lodash-to-ramda-example.html" rel="nofollow">http://bahmutov.calepin.co/lodash-to-ramda-example.html</a>
The author is misrepresenting imperative code [0].
Instead of the 42 lines of code he thinks is imperative, but really is already functional-compatible, this is what I would write:<p><pre><code> var getIncompleteTaskSummariesForMember_imperative = function(memberName) {
return fetchData().then(function(data) {
var tasks = data.tasks;
var results = [];
for (var i = 0; i < tasks.length; i++) {
var task = tasks[i];
if (task.member == memberName && !task.complete) {
results.push({
id: task.id,
dueDate: task.dueDate,
title: task.title,
priority: task.priority
})
}
}
results.sort(function(first, second) {
return first.dueDate - second.dueDate;
});
return results;
});
}
</code></pre>
Still longer than the 10 lines of functional code, but a much more fair comparison.<p>[0]: <a href="http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk/#slide-123" rel="nofollow">http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk...</a>
There is also @fogus' book: <a href="http://shop.oreilly.com/product/0636920028857.do" rel="nofollow">http://shop.oreilly.com/product/0636920028857.do</a><p>I haven't read it yet.
This is a really nice presentation that introduces a lot of concepts well and also helps a person conceptually understand how functional programming fits in to the larger programming world.<p>Book mark it and share it.
Intrestingly it seems that the functional version he proposed is much faster than the OO version. <a href="http://jsperf.com/oop-vs-ramda" rel="nofollow">http://jsperf.com/oop-vs-ramda</a>
I dislike these expositions on the "differences" between object-oriented and functional programming. The two concepts are not directly commensurable, and one can have objects with referentially transparent methods, to be used in a declarative style.
I believe this is the author of Ramda, yes?<p>I can't find the talk, anybody got a link?<p>(Ramda is pretty bad ass.) <a href="http://ramda.github.io/ramdocs/docs/" rel="nofollow">http://ramda.github.io/ramdocs/docs/</a>
I put together a similar talk last summer: <a href="http://thedrearlight.com/functional-js-wut" rel="nofollow">http://thedrearlight.com/functional-js-wut</a> unfortunately, don't have the vid either, but the slides might be complementary to the ones linked by the OP.<p>--edit
It's formatted kinda weird, where both up/down and left/right arrows navigate through the different sections.
Trying to ride the wave: I have written about functional programming in javascript, see blog posts <a href="http://bahmutov.calepin.co/tag/functional.html" rel="nofollow">http://bahmutov.calepin.co/tag/functional.html</a> - Ramda is great!
His functional example in Bluebird and some ES6 (traceur) just becomes:<p>```
return fetchData().get("tasks").filter(x => x.member === memberName).filter(x => !x.complete).map(x => {x.id, x.dueDate, x.title, x.priority}).call('sort');
```
Bravo for promoting functional programming and showing how it can be done in JavaScript. One issue concerns me, though: using strings to reference attributes. This makes static checking tools much less useful and can lead to difficult to find errors due to refactoring and typos.
See also
fn.js (Functional JavaScript Library)| <a href="https://bitbucket.org/ktg/fn" rel="nofollow">https://bitbucket.org/ktg/fn</a>