Skip to content

Instantly share code, notes, and snippets.

@andrew-templeton
Created May 20, 2015 21:30
Show Gist options
  • Save andrew-templeton/c36ef6efd0362e1c0203 to your computer and use it in GitHub Desktop.
Save andrew-templeton/c36ef6efd0362e1c0203 to your computer and use it in GitHub Desktop.
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