Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add oneOfAs #50

Closed
safareli opened this issue Apr 6, 2017 · 1 comment
Closed

add oneOfAs #50

safareli opened this issue Apr 6, 2017 · 1 comment

Comments

@safareli
Copy link
Contributor

safareli commented Apr 6, 2017

oneOfAs :: forall s m a. (StringLike s, Monad m) => Array (Tuple Char a) -> ParserT s m a

(Haven't seen such function and i came up with this name, so it could be changed)

This will allow to change something like this:

digit   m. Monad m  P.ParserT String m Int
digit = do
  char ← PS.oneOf ['0','1','2','3','4','5','6','7','8','9']
  case char of
    '0' → pure 0
    '1' → pure 1
    '2' → pure 2
    '3' → pure 3
    '4' → pure 4
    '5' → pure 5
    '6' → pure 6
    '7' → pure 7
    '8' → pure 8
    '9' → pure 9
    _ → P.fail "Incorrect digit, impossible situation"

to

digit   m. Monad m  P.ParserT String m Int
digit = PS.oneOfAs $
  [ Tuple '0' 0
  , Tuple '1' 1
  , Tuple '2' 2
  , Tuple '3' 3
  , Tuple '4' 4
  , Tuple '5' 5
  , Tuple '6' 6
  , Tuple '7' 7
  , Tuple '8' 8
  , Tuple '9' 9]
@safareli
Copy link
Contributor Author

safareli commented Apr 6, 2017

Is it something others want to have? if so iI could open PR as well

@safareli safareli mentioned this issue Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant