on master help sign in
Deprecate the "next" parser, use "one" fold instead
420f387Harendra Kumar
benchmark/Streamly/Benchmark/Data/Parser.hs+12−10
@@ -110,15 +110,17 @@ benchIOSink value name f =
110-- Parsers
110-- Parsers
111-------------------------------------------------------------------------------
111-------------------------------------------------------------------------------
112
112
113−{-# INLINE next #-}
113+{-# INLINE one #-}
114−next :: MonadCatch m => Int -> SerialT m Int -> m (Maybe Int)
114+one :: MonadCatch m => Int -> SerialT m Int -> m (Maybe Int)
115−next value = IP.parse p
115+one value = IP.parse p
116+
116− where
117+ where
118+
117− p = do
119+ p = do
118− m <- PR.next
120+ m <- PR.fromFold FL.one
119− case m of
121+ case m of
120− Just i -> if i >= value then pure m else p
122+ Just i -> if i >= value then pure m else p
121− Nothing -> pure Nothing
123+ Nothing -> pure Nothing
122
124
123{-# INLINE takeBetween #-}
125{-# INLINE takeBetween #-}
124takeBetween :: MonadCatch m => Int -> SerialT m a -> m ()
126takeBetween :: MonadCatch m => Int -> SerialT m a -> m ()
@@ -411,7 +413,7 @@ moduleName = "Data.Parser"
411
413
412o_1_space_serial :: Int -> [Benchmark]
414o_1_space_serial :: Int -> [Benchmark]
413o_1_space_serial value =
415o_1_space_serial value =
414− [ benchIOSink value "next" $ next value
416+ [ benchIOSink value "one (fold)" $ one value
415 , benchIOSink value "takeBetween" $ takeBetween value
417 , benchIOSink value "takeBetween" $ takeBetween value
416 , benchIOSink value "takeEQ" $ takeEQ value
418 , benchIOSink value "takeEQ" $ takeEQ value
417 , benchIOSink value "takeWhile" $ takeWhile value
419 , benchIOSink value "takeWhile" $ takeWhile value
core/src/Streamly/Internal/Data/Parser.hs+4−3
@@ -70,7 +70,6 @@ module Streamly.Internal.Data.Parser
70 -- * Element parsers
70 -- * Element parsers
71 , peek
71 , peek
72 , one
72 , one
73− , next
74 , element
73 , element
75 , except
74 , except
76 , oneOf
75 , oneOf
@@ -232,6 +231,9 @@ module Streamly.Internal.Data.Parser
232 , retryMaxTotal
231 , retryMaxTotal
233 , retryMaxSuccessive
232 , retryMaxSuccessive
234 , retry
233 , retry
234+
235+ -- * Deprecated
236+ , next
235 )
237 )
236where
238where
237
239
@@ -419,8 +421,6 @@ eof = D.toParserK D.eof
419satisfy :: MonadCatch m => (a -> Bool) -> Parser m a a
421satisfy :: MonadCatch m => (a -> Bool) -> Parser m a a
420satisfy = D.toParserK . D.satisfy
422satisfy = D.toParserK . D.satisfy
421
423
422−-- XXX Change this to "next".
423−--
424-- | Consume one element from the head of the stream. Fails if it encounters
424-- | Consume one element from the head of the stream. Fails if it encounters
425-- end of input.
425-- end of input.
426--
426--
@@ -485,6 +485,7 @@ noneOf xs = satisfy (`notElem` xs)
485--
485--
486-- /Pre-release/
486-- /Pre-release/
487--
487--
488+{-# DEPRECATED next "Please use \"fromFold Fold.one\" instead" #-}
488{-# INLINE next #-}
489{-# INLINE next #-}
489next :: MonadCatch m => Parser m a (Maybe a)
490next :: MonadCatch m => Parser m a (Maybe a)
490next = D.toParserK D.next
491next = D.toParserK D.next
test/Streamly/Test/Data/Parser.hs+12−12
@@ -155,18 +155,18 @@ satisfy =
155 where
155 where
156 predicate = (>= mid_value)
156 predicate = (>= mid_value)
157
157
158−nextPass :: Property
158+onePass :: Property
159−nextPass =
159+onePass =
160 forAll (chooseInt (1, max_value)) $ \int ->
160 forAll (chooseInt (1, max_value)) $ \int ->
161− property (case S.parse P.next (S.fromList [int]) of
161+ property (case S.parse P.one (S.fromList [int]) of
162− Right (Just i) -> i == int
162+ Right i -> i == int
163− _ -> False)
163+ Left _ -> False)
164
164
165−next :: Property
165+one :: Property
166−next =
166+one =
167− property (case S.parse P.next (S.fromList []) of
167+ property (case S.parse P.one (S.fromList []) of
168− Right Nothing -> True
168+ Left _ -> True
169− _ -> False)
169+ Right _ -> False)
170
170
171-- Sequence Parsers Tests
171-- Sequence Parsers Tests
172takeBetweenPass :: Property
172takeBetweenPass :: Property
@@ -1081,8 +1081,8 @@ main =
1081 prop "eof pass on []" eofPass
1081 prop "eof pass on []" eofPass
1082 prop "eof fail on non-empty list" eofFail
1082 prop "eof fail on non-empty list" eofFail
1083 prop "first element exists and >= mid_value" satisfyPass
1083 prop "first element exists and >= mid_value" satisfyPass
1084− prop "next pass on [Int]" nextPass
1084+ prop "one pass on [Int]" onePass
1085− prop "next fail on []" next
1085+ prop "one fail on []" one
1086 prop "check first element exists and satisfies predicate" satisfy
1086 prop "check first element exists and satisfies predicate" satisfy
1087
1087
1088 describe "test for sequence parser" $ do
1088 describe "test for sequence parser" $ do