Skip to content

Instantly share code, notes, and snippets.

@nagyadam2092
Last active May 21, 2021 05:06
Show Gist options
  • Save nagyadam2092/a44f59fa4729e1c9f3b2e306a4cffe7e to your computer and use it in GitHub Desktop.
Save nagyadam2092/a44f59fa4729e1c9f3b2e306a4cffe7e to your computer and use it in GitHub Desktop.
var Id = v => ({v: v,map: f => Id(f(v)) });
var CoFreeF = (a, next) => ({
a: a,
next: next,
extract: () => a,
map: g => CoFreeF(g(a), () => next().map(x=>x.map(g))),
});
var f = n => CoFreeF(n + 1, () => Id(f(n + 1)));
var stream = f(0);
console.log(stream)
var x = stream.next().v.next().v.map(x => x * 2).next().v;
console.log(x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment