Skip to content

Instantly share code, notes, and snippets.

@nagyadam2092
Created May 21, 2021 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagyadam2092/9eff3fb49dbd59cea873d907a48dcb09 to your computer and use it in GitHub Desktop.
Save nagyadam2092/9eff3fb49dbd59cea873d907a48dcb09 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