Skip to content

Commit 2096fce

Browse files
author
Nick Obedin
committed
* fixed 'satisfy'
1 parent e0e9c67 commit 2096fce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Text/Parsing/Parser/String.purs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ 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 = do
38-
p <- char
39-
if f p then return p else fail "Character did not satisfy predicate"
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") }
4044

4145
whiteSpace :: forall m. (Monad m) => ParserT String m String
4246
whiteSpace = do

0 commit comments

Comments
 (0)