Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created January 2, 2018 09:12
Show Gist options
  • Save zerobias/3ac3f79d0a8895040ad84a2109251891 to your computer and use it in GitHub Desktop.
Save zerobias/3ac3f79d0a8895040ad84a2109251891 to your computer and use it in GitHub Desktop.
Do notation in js
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