Skip to content

Commit 94e78b4

Browse files
author
Nick Obedin
committed
* improved solution
1 parent 2ea74e5 commit 94e78b4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/Text/Parsing/Parser/String.purs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ char = ParserT $ \s' ->
3434
_ -> { consumed: true, input: drop 1 s', result: Right (charAt 0 s') }
3535

3636
satisfy :: forall m. (Monad m) => (String -> Boolean) -> ParserT String m String
37-
satisfy f = ParserT $ \s' -> case s' of
38-
"" -> return { consumed: false, input: s', result: Left (strMsg "Unexpected EOF") }
39-
_ ->
40-
let c = charAt 0 s'
41-
in return $ if f c
42-
then { consumed: true, input: drop 1 s', result: Right c }
43-
else { consumed: false, input: s', result: Left (strMsg "Character did not satisfy predicate") }
37+
satisfy f = try do
38+
c <- char
39+
if f c then return c
40+
else fail "Character did not satisfied predicate"
4441

4542
whiteSpace :: forall m. (Monad m) => ParserT String m String
4643
whiteSpace = do

0 commit comments

Comments
 (0)