Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created December 23, 2015 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domgetter/8d4a336c60826b957bfd to your computer and use it in GitHub Desktop.
Save domgetter/8d4a336c60826b957bfd to your computer and use it in GitHub Desktop.
map = function(f) {
return function(rf) {
return function(acc, elem) {
return rf(acc, f(elem));
};
};
};
square = function(n) {return n*n;};
add = function(a,b) {return a+b;};
[1,2,3].reduce(map(square)(add));
// 14
notify = function(n) {console.log("Working on:", n); return n;};
[1,2,3].reduce(map(notify)(add), 0);
// Working on: 1
// Working on: 2
// Working on: 3
// 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment