on master help sign in
Fix Parser.eqBy.
commit959fcc7eec9d267da3b1d496506d71cfb13f37b1 authorPranay Sashank <pranaysashank@composewell.com> dateTue 2 Jun 2020, 18:55 (6 years ago) parent12ca6ee
2 files changed+8−3
src/Streamly/Internal/Data/Parser.hs+5 src/Streamly/Internal/Data/Parser/ParserD.hs+3−3
src/Streamly/Internal/Data/Parser.hs+5
@@ -570,6 +570,11 @@ groupBy = undefined
570570
571571-- | Match the given sequence of elements using the given comparison function.
572572--
573+-- >>> S.parse $ S.eqBy (==) "string" $ S.fromList "string"
574+--
575+-- >>> S.parse $ S.eqBy (==) "mismatch" $ S.fromList "match"
576+-- > *** Exception: ParseError "eqBy: failed, yet to match 7 elements"
577+--
573578-- /Internal/
574579--
575580{-# INLINE eqBy #-}
src/Streamly/Internal/Data/Parser/ParserD.hs+3−3
@@ -553,16 +553,16 @@ eqBy cmp str = Parser step initial extract
553553
554554 initial = return str
555555
556− step [] _ = error "Bug: unreachable"
556+ step [] _ = return $ Stop 0 ()
557557 step [x] a = return $
558558 if x `cmp` a
559559 then Stop 0 ()
560− else Error "eqBy: failed, at the last element"
560+ else Error "eqBy: failed, yet to match the last element"
561561 step (x:xs) a = return $
562562 if x `cmp` a
563563 then Skip 0 xs
564564 else Error $
565− "eqBy: failed, yet to match " ++ show (length xs) ++ " elements"
565+ "eqBy: failed, yet to match " ++ show (length xs + 1) ++ " elements"
566566
567567 extract xs = throwM $ ParseError $
568568 "eqBy: end of input, yet to match " ++ show (length xs) ++ " elements"