Skip to content

Instantly share code, notes, and snippets.

@stevekane
Last active October 27, 2016 16:09
Show Gist options
  • Save stevekane/51e038a59c5b9aa357ecb4a4f5611203 to your computer and use it in GitHub Desktop.
Save stevekane/51e038a59c5b9aa357ecb4a4f5611203 to your computer and use it in GitHub Desktop.
Monadic parsers in Typescript/Javascript
const parse_int =
then(or(match('-'), of('')), => s
then(many(isNumber), => digits
of(Number(s + digits))))
/*
in ML-style lang, this might look like this:
parse_int = do
s <- match '-' <|> unit ''
digits <- many number
Number(s + digits)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment