Last active
August 29, 2015 14:27
-
-
Save tuscen/6a8480c9cc3adfce44bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let compose = (...fns) => x => fns.reverse().reduce((acc, f) => f(acc), x); | |
let map = f => x => x.map(f); | |
let log = function() { | |
console.log(this); | |
return this; | |
}; | |
let toUpperCase = x => x.toUpperCase(); | |
let head = x => x[0]; | |
let initials = compose(s => s.join('. '), map(compose(toUpperCase, head)), x => x.split(' ')); | |
initials("hunter stockton thompson")::log(); // => H. S. T. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _context; | |
var compose = function compose() { | |
for (var _len = arguments.length, fns = Array(_len), _key = 0; _key < _len; _key++) { | |
fns[_key] = arguments[_key]; | |
} | |
return function (x) { | |
return fns.reverse().reduce(function (acc, f) { | |
return f(acc); | |
}, x); | |
}; | |
}; | |
var map = function map(f) { | |
return function (x) { | |
return x.map(f); | |
}; | |
}; | |
var log = function log() { | |
console.log(this); | |
return this; | |
}; | |
var toUpperCase = function toUpperCase(x) { | |
return x.toUpperCase(); | |
}; | |
var head = function head(x) { | |
return x[0]; | |
}; | |
var initials = compose(function (s) { | |
return s.join('. '); | |
}, map(compose(toUpperCase, head)), function (x) { | |
return x.split(' '); | |
}); | |
(_context = initials("hunter stockton thompson"), log).call(_context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment