Skip to content

Instantly share code, notes, and snippets.

@bwestergard
Last active August 29, 2015 14:26
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 bwestergard/d49a53fb5c8031605e37 to your computer and use it in GitHub Desktop.
Save bwestergard/d49a53fb5c8031605e37 to your computer and use it in GitHub Desktop.
Ramda "supercompiler"
// Ramda provides one, but just for verbosity
var add = function (x,y) { return x + y; };
var square = function (x) { return x * x; };
// Redundant looping
var sumSquares = R.pipe(
R.map(square),
R.reduce(add, 0)
);
// Drop one loop
var addSquare = function (x,y) { return x + square(y); };
var sumSquaresFast = R.reduce(addSquare, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment