on master help sign in
Rename drainWhile parser to dropWhile
commit769564d62778939f0b22d445d896d65fb0a1194c authorHarendra Kumar <harendra@composewell.com> dateWed 4 May 2022, 19:44 (4 years ago) parent43dda21
2 files changed+31−30
benchmark/Streamly/Benchmark/Data/Parser.hs+24−24 core/src/Streamly/Internal/Data/Parser.hs+7−6
benchmark/Streamly/Benchmark/Data/Parser.hs+24−24
@@ -23,8 +23,8 @@ import GHC.Magic (inline)
2323import GHC.Magic (noinline)
2424import System.IO (Handle)
2525import System.Random (randomRIO)
26−import Prelude
27− hiding (any, all, take, sequence, sequence_, sequenceA, takeWhile)
26+import Prelude hiding
27+ (any, all, take, sequence, sequence_, sequenceA, takeWhile, dropWhile)
2828
2929import qualified Data.Traversable as TR
3030import qualified Data.Foldable as F
@@ -88,9 +88,9 @@ takeBetween value = IP.parse (PR.takeBetween 0 value FL.drain)
8888takeEQ :: MonadCatch m => Int -> SerialT m a -> m ()
8989takeEQ value = IP.parse (PR.takeEQ value FL.drain)
9090
91−{-# INLINE drainWhile #-}
92−drainWhile :: MonadCatch m => Int -> SerialT m Int -> m ()
93−drainWhile value = IP.parse (PR.drainWhile (<= value))
91+{-# INLINE dropWhile #-}
92+dropWhile :: MonadCatch m => Int -> SerialT m Int -> m ()
93+dropWhile value = IP.parse (PR.dropWhile (<= value))
9494
9595{-# INLINE sliceBeginWith #-}
9696sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
@@ -154,8 +154,8 @@ splitAp :: MonadCatch m
154154splitAp value =
155155 IP.parse
156156 ((,)
157− <$> PR.drainWhile (<= (value `div` 2))
158− <*> PR.drainWhile (<= value)
157+ <$> PR.dropWhile (<= (value `div` 2))
158+ <*> PR.dropWhile (<= value)
159159 )
160160
161161{-# INLINE splitApBefore #-}
@@ -163,8 +163,8 @@ splitApBefore :: MonadCatch m
163163 => Int -> SerialT m Int -> m ()
164164splitApBefore value =
165165 IP.parse
166− ( PR.drainWhile (<= (value `div` 2))
167− *> PR.drainWhile (<= value)
166+ ( PR.dropWhile (<= (value `div` 2))
167+ *> PR.dropWhile (<= value)
168168 )
169169
170170{-# INLINE splitApAfter #-}
@@ -172,8 +172,8 @@ splitApAfter :: MonadCatch m
172172 => Int -> SerialT m Int -> m ()
173173splitApAfter value =
174174 IP.parse
175− ( PR.drainWhile (<= (value `div` 2))
176− <* PR.drainWhile (<= value)
175+ ( PR.dropWhile (<= (value `div` 2))
176+ <* PR.dropWhile (<= value)
177177 )
178178
179179{-# INLINE serialWith #-}
@@ -182,8 +182,8 @@ serialWith :: MonadCatch m
182182serialWith value =
183183 IP.parse
184184 (PR.serialWith (,)
185− (PR.drainWhile (<= (value `div` 2)))
186− (PR.drainWhile (<= value))
185+ (PR.dropWhile (<= (value `div` 2)))
186+ (PR.dropWhile (<= value))
187187 )
188188
189189{-# INLINE split_ #-}
@@ -192,8 +192,8 @@ split_ :: MonadCatch m
192192split_ value =
193193 IP.parse
194194 (PR.split_
195− (PR.drainWhile (<= (value `div` 2)))
196− (PR.drainWhile (<= value))
195+ (PR.dropWhile (<= (value `div` 2)))
196+ (PR.dropWhile (<= value))
197197 )
198198
199199{-# INLINE sliceSepByP #-}
@@ -207,8 +207,8 @@ teeAllAny :: MonadCatch m
207207teeAllAny value =
208208 IP.parse
209209 (PR.teeWith (,)
210− (PR.drainWhile (<= value))
211− (PR.drainWhile (<= value))
210+ (PR.dropWhile (<= value))
211+ (PR.dropWhile (<= value))
212212 )
213213
214214{-# INLINE teeFstAllAny #-}
@@ -217,8 +217,8 @@ teeFstAllAny :: MonadCatch m
217217teeFstAllAny value =
218218 IP.parse
219219 (PR.teeWithFst (,)
220− (PR.drainWhile (<= value))
221− (PR.drainWhile (<= value))
220+ (PR.dropWhile (<= value))
221+ (PR.dropWhile (<= value))
222222 )
223223
224224{-# INLINE shortestAllAny #-}
@@ -227,8 +227,8 @@ shortestAllAny :: MonadCatch m
227227shortestAllAny value =
228228 IP.parse
229229 (PR.shortest
230− (PR.drainWhile (<= value))
231− (PR.drainWhile (<= value))
230+ (PR.dropWhile (<= value))
231+ (PR.dropWhile (<= value))
232232 )
233233
234234{-# INLINE longestAllAny #-}
@@ -237,8 +237,8 @@ longestAllAny :: MonadCatch m
237237longestAllAny value =
238238 IP.parse
239239 (PR.longest
240− (PR.drainWhile (<= value))
241− (PR.drainWhile (<= value))
240+ (PR.dropWhile (<= value))
241+ (PR.dropWhile (<= value))
242242 )
243243
244244parseManyChunksOfSum :: Int -> Handle -> IO Int
@@ -345,7 +345,7 @@ o_1_space_serial value =
345345 , benchIOSink value "takeEQ" $ takeEQ value
346346 , benchIOSink value "takeWhile" $ takeWhile value
347347 , benchIOSink value "takeP" $ takeP value
348− , benchIOSink value "drainWhile" $ drainWhile value
348+ , benchIOSink value "dropWhile" $ dropWhile value
349349 , benchIOSink value "sliceBeginWith" $ sliceBeginWith value
350350 , benchIOSink value "groupBy" $ groupBy
351351 , benchIOSink value "groupByRolling" $ groupByRolling
core/src/Streamly/Internal/Data/Parser.hs+7−6
@@ -100,7 +100,7 @@ module Streamly.Internal.Data.Parser
100100 , takeWhile
101101 -- $takeWhile
102102 , takeWhile1
103− , drainWhile
103+ , dropWhile
104104
105105 -- Separators
106106 , sliceSepByP
@@ -223,7 +223,8 @@ import Control.Applicative ((<|>))
223223import Control.Monad.Catch (MonadCatch, MonadThrow)
224224import Data.Functor (($>))
225225import Prelude hiding
226− (any, all, take, takeWhile, sequence, concatMap, maybe, either, filter)
226+ ( any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either
227+ , filter )
227228
228229import Streamly.Internal.Data.Fold.Type (Fold(..))
229230import Streamly.Internal.Data.Parser.ParserK.Type (Parser)
@@ -236,7 +237,7 @@ import qualified Streamly.Internal.Data.Parser.ParserK.Type as K
236237-- $setup
237238-- >>> :m
238239-- >>> :set -package streamly
239−-- >>> import Prelude hiding (any, all, take, takeWhile, sequence, concatMap, maybe, either)
240+-- >>> import Prelude hiding (any, all, dropWhile, take, takeWhile, sequence, concatMap, maybe, either, filter)
240241-- >>> import qualified Streamly.Prelude as Stream
241242-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (parse, parseMany)
242243-- >>> import qualified Streamly.Data.Fold as Fold
@@ -634,9 +635,9 @@ takeWhile1 cond = D.toParserK . D.takeWhile1 cond
634635--
635636-- /Pre-release/
636637--
637−{-# INLINE drainWhile #-}
638−drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
639−drainWhile p = takeWhile p FL.drain
638+{-# INLINE dropWhile #-}
639+dropWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
640+dropWhile p = takeWhile p FL.drain
640641
641642-------------------------------------------------------------------------------
642643-- Separators