Last active
March 2, 2017 06:34
-
-
Save ccorcos/487a1572d4d68c7528c2d94cc27a226a to your computer and use it in GitHub Desktop.
This file contains 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
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