Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active October 7, 2016 11:32
Show Gist options
  • Save ryasmi/dc3158855be46078f43e to your computer and use it in GitHub Desktop.
Save ryasmi/dc3158855be46078f43e to your computer and use it in GitHub Desktop.
Example of lazy evaluation in JavaScript?
const add = a => b => () => a() + b();
const one = () => 1
add(add(one)(one))(one)(); // 3
add = function (a) {
return function (b) {
return function () {
a = a();
b = b();
return a + b;
};
};
};
one = function () {return 1;};
add(add(one)(one))(one)(); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment