on master help sign in
Deprecate the "next" parser, use "one" fold instead
commit420f387a207b90ac4a3f23f546a8be2983eddb4f authorHarendra Kumar <harendra@composewell.com> dateWed 18 May 2022, 19:42 (4 years ago) parent8230747
3 files changed+28−25
benchmark/Streamly/Benchmark/Data/Parser.hs+12−10 core/src/Streamly/Internal/Data/Parser.hs+4−3 test/Streamly/Test/Data/Parser.hs+12−12
benchmark/Streamly/Benchmark/Data/Parser.hs+12−10
@@ -110,15 +110,17 @@ benchIOSink value name f =
110110-- Parsers
111111-------------------------------------------------------------------------------
112112
113−{-# INLINE next #-}
114−next :: MonadCatch m => Int -> SerialT m Int -> m (Maybe Int)
115−next value = IP.parse p
116− where
117− p = do
118− m <- PR.next
119− case m of
120− Just i -> if i >= value then pure m else p
121− Nothing -> pure Nothing
113+{-# INLINE one #-}
114+one :: MonadCatch m => Int -> SerialT m Int -> m (Maybe Int)
115+one value = IP.parse p
116+
117+ where
118+
119+ p = do
120+ m <- PR.fromFold FL.one
121+ case m of
122+ Just i -> if i >= value then pure m else p
123+ Nothing -> pure Nothing
122124
123125{-# INLINE takeBetween #-}
124126takeBetween :: MonadCatch m => Int -> SerialT m a -> m ()
@@ -411,7 +413,7 @@ moduleName = "Data.Parser"
411413
412414o_1_space_serial :: Int -> [Benchmark]
413415o_1_space_serial value =
414− [ benchIOSink value "next" $ next value
416+ [ benchIOSink value "one (fold)" $ one value
415417 , benchIOSink value "takeBetween" $ takeBetween value
416418 , benchIOSink value "takeEQ" $ takeEQ value
417419 , benchIOSink value "takeWhile" $ takeWhile value
core/src/Streamly/Internal/Data/Parser.hs+4−3
@@ -70,7 +70,6 @@ module Streamly.Internal.Data.Parser
7070 -- * Element parsers
7171 , peek
7272 , one
73− , next
7473 , element
7574 , except
7675 , oneOf
@@ -232,6 +231,9 @@ module Streamly.Internal.Data.Parser
232231 , retryMaxTotal
233232 , retryMaxSuccessive
234233 , retry
234+
235+ -- * Deprecated
236+ , next
235237 )
236238where
237239
@@ -419,8 +421,6 @@ eof = D.toParserK D.eof
419421satisfy :: MonadCatch m => (a -> Bool) -> Parser m a a
420422satisfy = D.toParserK . D.satisfy
421423
422−-- XXX Change this to "next".
423−--
424424-- | Consume one element from the head of the stream. Fails if it encounters
425425-- end of input.
426426--
@@ -485,6 +485,7 @@ noneOf xs = satisfy (`notElem` xs)
485485--
486486-- /Pre-release/
487487--
488+{-# DEPRECATED next "Please use \"fromFold Fold.one\" instead" #-}
488489{-# INLINE next #-}
489490next :: MonadCatch m => Parser m a (Maybe a)
490491next = D.toParserK D.next
test/Streamly/Test/Data/Parser.hs+12−12
@@ -155,18 +155,18 @@ satisfy =
155155 where
156156 predicate = (>= mid_value)
157157
158−nextPass :: Property
159−nextPass =
158+onePass :: Property
159+onePass =
160160 forAll (chooseInt (1, max_value)) $ \int ->
161− property (case S.parse P.next (S.fromList [int]) of
162− Right (Just i) -> i == int
163− _ -> False)
161+ property (case S.parse P.one (S.fromList [int]) of
162+ Right i -> i == int
163+ Left _ -> False)
164164
165−next :: Property
166−next =
167− property (case S.parse P.next (S.fromList []) of
168− Right Nothing -> True
169− _ -> False)
165+one :: Property
166+one =
167+ property (case S.parse P.one (S.fromList []) of
168+ Left _ -> True
169+ Right _ -> False)
170170
171171-- Sequence Parsers Tests
172172takeBetweenPass :: Property
@@ -1081,8 +1081,8 @@ main =
10811081 prop "eof pass on []" eofPass
10821082 prop "eof fail on non-empty list" eofFail
10831083 prop "first element exists and >= mid_value" satisfyPass
1084− prop "next pass on [Int]" nextPass
1085− prop "next fail on []" next
1084+ prop "one pass on [Int]" onePass
1085+ prop "one fail on []" one
10861086 prop "check first element exists and satisfies predicate" satisfy
10871087
10881088 describe "test for sequence parser" $ do