THIS POST IS A WORK IN PROGRESS

As I continue my dive into functional programming in earnest, I am finding more and more things that I really enjoy about the paradigm.

Two of my favorites so far a composition and currying.

Composition is the method by which I can pass an arbitrary number of functions

1 _ = require('./ramda.min.js');
2 
3 // Compose
4 var uppercase = function(str) { return str.toUpperCase(); }
5 var scream = function(str) { return str + "!!!"; }
6 var hello = function(str) { return "Hello, " + str; }
7 var momSMS = _.compose(hello, scream, uppercase);
8 console.log(momSMS("Ted"));
$ node compose_example.js
=> Hello, TED!!!
1 // Curry
2 var addN = function(n, m) { return n + m };
3 var curryAddN = _.curry(addN)
4 var add10 = curryAddN(10)
5 var add100 = curryAddN(100)
6 console.log(add10(15));
7 console.log(add100(15));
$ node curry_example.js
=> 25
115


blog comments powered by Disqus

Published

16 August 2015