on master help sign in
Fix Parser.eqBy.
959fcc7Pranay Sashank
src/Streamly/Internal/Data/Parser.hs+5
@@ -570,6 +570,11 @@ groupBy = undefined
570
570
571-- | Match the given sequence of elements using the given comparison function.
571-- | Match the given sequence of elements using the given comparison function.
572--
572--
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+--
573-- /Internal/
578-- /Internal/
574--
579--
575{-# INLINE eqBy #-}
580{-# INLINE eqBy #-}
src/Streamly/Internal/Data/Parser/ParserD.hs+3−3
@@ -553,16 +553,16 @@ eqBy cmp str = Parser step initial extract
553
553
554 initial = return str
554 initial = return str
555
555
556− step [] _ = error "Bug: unreachable"
556+ step [] _ = return $ Stop 0 ()
557 step [x] a = return $
557 step [x] a = return $
558 if x `cmp` a
558 if x `cmp` a
559 then Stop 0 ()
559 then Stop 0 ()
560− else Error "eqBy: failed, at the last element"
560+ else Error "eqBy: failed, yet to match the last element"
561 step (x:xs) a = return $
561 step (x:xs) a = return $
562 if x `cmp` a
562 if x `cmp` a
563 then Skip 0 xs
563 then Skip 0 xs
564 else Error $
564 else Error $
565− "eqBy: failed, yet to match " ++ show (length xs) ++ " elements"
565+ "eqBy: failed, yet to match " ++ show (length xs + 1) ++ " elements"
566
566
567 extract xs = throwM $ ParseError $
567 extract xs = throwM $ ParseError $
568 "eqBy: end of input, yet to match " ++ show (length xs) ++ " elements"
568 "eqBy: end of input, yet to match " ++ show (length xs) ++ " elements"