Skip to content

Instantly share code, notes, and snippets.

@haf
Created December 1, 2017 15:35
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 haf/76520e528c291e14dd73cf817bf3b489 to your computer and use it in GitHub Desktop.
Save haf/76520e528c291e14dd73cf817bf3b489 to your computer and use it in GitHub Desktop.
function unfoldWith(fn) {
return value => {
let a = [],
{ next, element, done } = fn(value);
while (!done) {
a.push(element);
({ next, element, done } = fn(next));
}
return a;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment