Created
January 2, 2018 09:12
-
-
Save zerobias/3ac3f79d0a8895040ad84a2109251891 to your computer and use it in GitHub Desktop.
Do notation in js
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
export function Do(generatorFunction) { | |
const generator = generatorFunction() | |
return function next(error, v) { | |
const res = generator.next(v) | |
if (res.done) | |
return res.value | |
else | |
return res.value.chain((v) => next(null, v) || res.value.of(v)) | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment