Created
December 1, 2017 15:35
-
-
Save haf/76520e528c291e14dd73cf817bf3b489 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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