Skip to content

Instantly share code, notes, and snippets.

@kylehovey
Created February 25, 2020 02:49
Show Gist options
  • Save kylehovey/567c223ae933408e25f7165a50ea1c33 to your computer and use it in GitHub Desktop.
Save kylehovey/567c223ae933408e25f7165a50ea1c33 to your computer and use it in GitHub Desktop.
const mkWrapper = () => (
cache => f => n => n in cache
? cache[n]
: cache[n] = f(n)
)([]);
const M = f => f(f);
const Y = f => (
wrapper => M(
maker => n => wrapper(
f(M(maker))
)(n)
)
)(mkWrapper());
const fact = Y(self => n => (
console.log(n),
n <= 0
? 1
: n * self(n-1)
)
);
console.log(fact(6));
console.log(fact(7));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment