Created
August 12, 2014 22:17
-
-
Save yanatan16/35d3d44c3c5aa81eee63 to your computer and use it in GitHub Desktop.
functional.goooooal.js
This file contains 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
// this a lazy evaluation of the delayed value | |
// If the delayed value is delayed (i.e. a function), then return a function that will resolve eventually | |
// If not, then resolve immediately and prefix | |
function resolve(prefix, delayed_value) { | |
if (typeof delayed_value === 'function') | |
return function (a) { return resolve(prefix, delayed_value(a)) } | |
else | |
return prefix + delayed_value | |
} | |
// If passed a value, return it | |
// otherwise return a recursive lazy evaluation prefixing 'o' | |
function oooos(a) { | |
if (a) | |
return a | |
else | |
return resolve('o', oooos) | |
} | |
// return an evaluated lazy evaluation of `oooos` prefixed with 'g' | |
function g(a) { | |
return resolve('g', oooos)(a) | |
} |
This file contains 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 r(p,f) { return f.bind ? function (a) { return r(p,f(a)) } : p+f } | |
function z(a) { return a ? a : r('o',z) } | |
function g(a) { return r('g',z)(a) } |
This file contains 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
> g('al') | |
'gal' | |
> g()('al') | |
'goal' | |
> g()()()()('al') | |
'gooooal' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment