on master help sign in
Change the signature of Parser.deintercalate, move fold at end (#1904)
commit61eb3f4dfada2c1e36096162045df84d86dd3d8c authorRanjeet Ranjan <ranjeetr@composewell.com> dateFri 7 Oct 2022, 13:51 (4 years ago) parente061109
4 files changed+11−11
benchmark/Streamly/Benchmark/Data/Parser.hs+1−1 core/src/Streamly/Internal/Data/Parser.hs+5−5 core/src/Streamly/Internal/Data/Parser/ParserD.hs+4−4 test/Streamly/Test/Data/Parser.hs+1−1
benchmark/Streamly/Benchmark/Data/Parser.hs+1−1
@@ -199,7 +199,7 @@ deintercalate _ = Stream.parse (partition even)
199199
200200 partition p =
201201 PR.deintercalate
202− Fold.drain (PR.takeWhile (not . p) Fold.sum) (PR.takeWhile p Fold.sum)
202+ (PR.takeWhile (not . p) Fold.sum) (PR.takeWhile p Fold.sum) Fold.drain
203203
204204{-# INLINE manyWordByEven #-}
205205manyWordByEven :: MonadThrow m => Stream m Int -> m ()
core/src/Streamly/Internal/Data/Parser.hs+5−5
@@ -1446,14 +1446,14 @@ manyThen _parser _recover _f = undefined
14461446--
14471447{-# INLINE deintercalate #-}
14481448deintercalate :: Monad m =>
1449− Fold m (Either x y) z
1450− -> Parser m a x
1449+ Parser m a x
14511450 -> Parser m a y
1451+ -> Fold m (Either x y) z
14521452 -> Parser m a z
1453−deintercalate sink contentL contentR =
1453+deintercalate contentL contentR sink =
14541454 D.toParserK
14551455 $ D.deintercalate
1456− sink (D.fromParserK contentL) (D.fromParserK contentR)
1456+ (D.fromParserK contentL) (D.fromParserK contentR) sink
14571457
14581458-- | Parse items separated by a separator parsed by the supplied parser. At
14591459-- least one item must be present for the parser to succeed.
@@ -1474,7 +1474,7 @@ sepBy1 sink p sep = do
14741474-- run, when it is done content parser is run again and so on. If none of the
14751475-- parsers consumes an input then parser returns a failure.
14761476--
1477−-- >>> sepBy sink = Parser.deintercalate (Fold.lefts sink)
1477+-- >>> sepBy sink p1 p2 = Parser.deintercalate p1 p2 (Fold.lefts sink)
14781478-- >>> sepBy sink content sep = Parser.sepBy1 sink content sep <|> return mempty
14791479--
14801480{-# INLINE sepBy #-}
core/src/Streamly/Internal/Data/Parser/ParserD.hs+4−4
@@ -1835,14 +1835,14 @@ data DeintercalateState fs sp ss =
18351835--
18361836{-# INLINE deintercalate #-}
18371837deintercalate :: Monad m =>
1838− Fold m (Either x y) z
1839− -> Parser m a x
1838+ Parser m a x
18401839 -> Parser m a y
1840+ -> Fold m (Either x y) z
18411841 -> Parser m a z
18421842deintercalate
1843− (Fold fstep finitial fextract)
18441843 (Parser stepL initialL extractL)
1845− (Parser stepR initialR extractR) = Parser step initial extract
1844+ (Parser stepR initialR extractR)
1845+ (Fold fstep finitial fextract) = Parser step initial extract
18461846
18471847 where
18481848
test/Streamly/Test/Data/Parser.hs+1−1
@@ -605,7 +605,7 @@ deintercalate =
605605 partition =
606606 FL.tee (fmap concat $ FL.lefts FL.toList)
607607 (fmap concat $ FL.rights FL.toList)
608− p = P.deintercalate partition p1 p2
608+ p = P.deintercalate p1 p2 partition
609609
610610-- shortestPass :: Property
611611-- shortestPass =