on master help sign in
Rename eqBy to streamEqBy in parsers
commit8cca012534af22e41b7f360ed51a5633db0efc6b authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateWed 7 Dec 2022, 10:17 (4 years ago) parent1c3d3f5
5 files changed+25−29
benchmark/Streamly/Benchmark/Data/Parser.hs+4−4 benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+4−4 core/src/Streamly/Data/Parser.hs+1−1 core/src/Streamly/Internal/Data/Parser.hs+8−12 core/src/Streamly/Internal/Data/Parser/ParserD.hs+8−8
benchmark/Streamly/Benchmark/Data/Parser.hs+4−4
@@ -160,9 +160,9 @@ takeFramedByEsc_ _ = Stream.parse parser
160160listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
161161listEqBy len = Stream.parse (PR.listEqBy (==) [1 .. len])
162162
163−{-# INLINE eqBy #-}
164−eqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
165−eqBy len = Stream.parse (PR.eqBy (==) (Stream.enumerateFromTo 1 len))
163+{-# INLINE streamEqBy #-}
164+streamEqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
165+streamEqBy len = Stream.parse (PR.streamEqBy (==) (Stream.enumerateFromTo 1 len))
166166
167167{-# INLINE takeWhile #-}
168168takeWhile :: Monad m => Int -> Stream m Int -> m (Either ParseError ())
@@ -492,7 +492,7 @@ o_1_space_serial value =
492492 , benchIOSink value "parseMany (groupBy (<))" (parseManyGroupBy (<))
493493 , benchIOSink value "parseMany (groupBy (==))" (parseManyGroupBy (==))
494494 , benchIOSink value "listEqBy" (listEqBy value)
495− , benchIOSink value "eqBy" (eqBy value)
495+ , benchIOSink value "streamEqBy" (streamEqBy value)
496496 ]
497497
498498o_1_space_filesystem :: BenchEnv -> [Benchmark]
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+4−4
@@ -73,9 +73,9 @@ benchIOSink value name f =
7373listEqBy :: Int -> Stream IO Int -> IO (Either ParseError [Int])
7474listEqBy len = Stream.parseD (PR.listEqBy (==) [1 .. len])
7575
76−{-# INLINE eqBy #-}
77−eqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
78−eqBy len = Stream.parseD (PR.eqBy (==) (D.enumerateFromToIntegral 1 len))
76+{-# INLINE streamEqBy #-}
77+streamEqBy :: Int -> Stream IO Int -> IO (Either ParseError ())
78+streamEqBy len = Stream.parseD (PR.streamEqBy (==) (D.enumerateFromToIntegral 1 len))
7979
8080{-# INLINE drainWhile #-}
8181drainWhile :: Monad m => (a -> Bool) -> PR.Parser a m ()
@@ -367,7 +367,7 @@ o_1_space_serial value =
367367 -}
368368 , benchIOSink value "sequenceParser" sequenceParser
369369 , benchIOSink value "listEqBy" (listEqBy value)
370− , benchIOSink value "eqBy" (eqBy value)
370+ , benchIOSink value "streamEqBy" (streamEqBy value)
371371 ]
372372
373373o_1_space_serial_spanning :: Int -> [Benchmark]
core/src/Streamly/Data/Parser.hs+1−1
@@ -51,7 +51,7 @@ module Streamly.Data.Parser
5151 -- , either
5252
5353 -- ** Sequences
54− , eqBy
54+ , streamEqBy
5555 , listEqBy
5656 , listEq
5757
core/src/Streamly/Internal/Data/Parser.hs+8−12
@@ -104,7 +104,7 @@ module Streamly.Internal.Data.Parser
104104 -- ** Exact match
105105 , listEq
106106 , listEqBy
107− , eqBy
107+ , streamEqBy
108108 , subsequenceBy
109109
110110 -- ** By predicate
@@ -1000,25 +1000,21 @@ groupByRollingEither :: Monad m =>
10001000 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
10011001groupByRollingEither eq f1 = D.toParserK . D.groupByRollingEither eq f1
10021002
1003−-- XXX eqBy is not a good name because we are not matching the entire stream
1004−-- unlike the eqBy in Stream module. matchStreamBy, matchStream, matchListBy,
1005−-- matchList.
1006−
10071003-- | Like 'listEqBy' but uses a stream instead of a list and does not return
10081004-- the stream.
10091005--
1010−-- See also: "Streamly.Data.Stream.eqBy"
1006+-- See also: "Streamly.Data.Stream.streamEqBy"
10111007--
1012−{-# INLINE eqBy #-}
1013−eqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser a m ()
1014−eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
1008+{-# INLINE streamEqBy #-}
1009+streamEqBy :: Monad m => (a -> a -> Bool) -> Stream m a -> Parser a m ()
1010+streamEqBy cmp = D.toParserK . D.streamEqBy cmp . Stream.toStreamD
10151011
10161012-- | Match the given sequence of elements using the given comparison function.
10171013-- Returns the original sequence if successful.
10181014--
10191015-- Definition:
10201016--
1021−-- >>> listEqBy cmp xs = Parser.eqBy cmp (Stream.fromList xs) *> Parser.fromPure xs
1017+-- >>> listEqBy cmp xs = Parser.streamEqBy cmp (Stream.fromList xs) *> Parser.fromPure xs
10221018--
10231019-- Examples:
10241020--
@@ -1026,12 +1022,12 @@ eqBy cmp = D.toParserK . D.eqBy cmp . Stream.toStreamD
10261022-- Right "string"
10271023--
10281024-- >>> Stream.parse (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
1029−-- Left (ParseError "eqBy: mismtach occurred")
1025+-- Left (ParseError "streamEqBy: mismtach occurred")
10301026--
10311027{-# INLINE listEqBy #-}
10321028listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser a m [a]
10331029-- listEqBy cmp xs = D.toParserK (D.listEqBy cmp xs)
1034−listEqBy cmp xs = eqBy cmp (Stream.fromList xs) *> fromPure xs
1030+listEqBy cmp xs = streamEqBy cmp (Stream.fromList xs) *> fromPure xs
10351031
10361032-- Rename to "list".
10371033-- | Match the input sequence with the supplied list and return it if
core/src/Streamly/Internal/Data/Parser/ParserD.hs+8−8
@@ -92,7 +92,7 @@ module Streamly.Internal.Data.Parser.ParserD
9292
9393 -- Matching strings
9494 , listEqBy
95− , eqBy
95+ , streamEqBy
9696 -- , prefixOf -- match any prefix of a given string
9797 -- , suffixOf -- match any suffix of a given string
9898 -- , infixOf -- match any substring of a given string
@@ -1469,7 +1469,7 @@ groupByRollingEither
14691469-- XXX custom combinators for matching list, array and stream?
14701470-- XXX rename to listBy?
14711471--
1472−-- | See 'Streamly.Internal.Data.Parser.eqBy'.
1472+-- | See 'Streamly.Internal.Data.Parser.streamEqBy'.
14731473--
14741474-- /Pre-release/
14751475--
@@ -1503,9 +1503,9 @@ listEqBy cmp str = Parser step initial extract
15031503 ++ show (length xs) ++ " elements"
15041504
15051505-- | Like 'listEqBy' but uses a stream instead of a list
1506−{-# INLINE eqBy #-}
1507−eqBy :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
1508−eqBy cmp (D.Stream sstep state) = Parser step initial extract
1506+{-# INLINE streamEqBy #-}
1507+streamEqBy :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
1508+streamEqBy cmp (D.Stream sstep state) = Parser step initial extract
15091509
15101510 where
15111511
@@ -1526,7 +1526,7 @@ eqBy cmp (D.Stream sstep state) = Parser step initial extract
15261526 D.Yield x1 s -> Continue 0 (Just' x1, s)
15271527 D.Stop -> Done 0 ()
15281528 D.Skip s -> Continue 1 (Nothing', s)
1529− else return $ Error "eqBy: mismtach occurred"
1529+ else return $ Error "streamEqBy: mismtach occurred"
15301530 step (Nothing', st) a = do
15311531 r <- sstep defState st
15321532 return
@@ -1534,11 +1534,11 @@ eqBy cmp (D.Stream sstep state) = Parser step initial extract
15341534 D.Yield x s -> do
15351535 if x `cmp` a
15361536 then Continue 0 (Nothing', s)
1537− else Error "eqBy: mismatch occurred"
1537+ else Error "streamEqBy: mismatch occurred"
15381538 D.Stop -> Done 1 ()
15391539 D.Skip s -> Continue 1 (Nothing', s)
15401540
1541− extract _ = return $ Error "eqBy: end of input"
1541+ extract _ = return $ Error "streamEqBy: end of input"
15421542
15431543-------------------------------------------------------------------------------
15441544-- Transformations on input