Created
May 20, 2015 21:30
-
-
Save andrew-templeton/c36ef6efd0362e1c0203 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function add(x, y) { | |
return x + y; | |
} | |
function toThe(pow) { | |
return function(base) { | |
return Math.pow(base, pow); | |
}; | |
} | |
function pipeline() { | |
return [].reduce.bind(arguments, function(soFar, nextFn) { | |
return nextFn(soFar); | |
}); | |
} | |
function lambda(func) { | |
return function() { | |
var args = [].slice.call(arguments, 0); | |
return function(context) { | |
return func.apply(context, args); | |
}; | |
}; | |
} | |
var mapBy = lambda([].map); | |
var reduceBy = lambda([].reduce); | |
function get() { | |
var args = [].slice.call(arguments, 0); | |
return function(obj) { | |
return args.reduce(function(hash, nextKey) { | |
return hash && hash[nextKey]; | |
}, obj); | |
}; | |
} | |
var getHits = get('hits', 'hits'); | |
var getThumbnails = mapBy(get('_source', 'thumbnail')); | |
var forwardImages = pipeline(getHits, getThumbnails, callback); | |
$http.get(someEndopint).success(forwardImages); | |
var magnitude = pipeline( | |
mapBy(toThe(2)), | |
reduceBy(add, 0), | |
Math.sqrt | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment