Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Last active March 2, 2017 06:34
Show Gist options
  • Save ccorcos/487a1572d4d68c7528c2d94cc27a226a to your computer and use it in GitHub Desktop.
Save ccorcos/487a1572d4d68c7528c2d94cc27a226a to your computer and use it in GitHub Desktop.
const where = predicate =>
new Parser(stream => {
if (stream.length === 0) {
return new Failure('unexpected end', stream)
}
const value = stream.head()
if (predicate(value)) {
return new Success(value, stream.move(1))
}
return new Failure('predicate did not match', stream)
})
const char = c => where(x => x === c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment