Last active
October 7, 2016 11:32
-
-
Save ryasmi/dc3158855be46078f43e to your computer and use it in GitHub Desktop.
Example of lazy evaluation in JavaScript?
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
const add = a => b => () => a() + b(); | |
const one = () => 1 | |
add(add(one)(one))(one)(); // 3 |
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
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