on master help sign in
Remove map from Internal.Data.Fold
commit8d9396711c3e7e3632ee8ce85563c5d58938afbd authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 26 Aug 2021, 11:49 (5 years ago) parent567c3bb
4 files changed+11−20
benchmark/Streamly/Benchmark/Data/Fold.hs+5−5 src/Streamly/Internal/Data/Array/Stream/Foreign.hs+1−1 src/Streamly/Internal/Data/Fold.hs+4−5 src/Streamly/Internal/Data/Fold/Type.hs+1−9
benchmark/Streamly/Benchmark/Data/Fold.hs+5−5
@@ -142,7 +142,7 @@ partition =
142142 if odd a
143143 then Left a
144144 else Right a
145− in IP.fold $ FL.map f (FL.partition FL.sum FL.length)
145+ in IP.fold $ FL.lmap f (FL.partition FL.sum FL.length)
146146
147147{-# INLINE demuxWith #-}
148148demuxWith ::
@@ -160,7 +160,7 @@ demuxDefaultWith ::
160160 -> Map k (Fold m b b)
161161 -> SerialT m a
162162 -> m (Map k b, b)
163−demuxDefaultWith f mp = S.fold (FL.demuxDefaultWith f mp (FL.map snd FL.sum))
163+demuxDefaultWith f mp = S.fold (FL.demuxDefaultWith f mp (FL.lmap snd FL.sum))
164164
165165{-# INLINE classifyWith #-}
166166classifyWith ::
@@ -173,7 +173,7 @@ classifyWith f = S.fold (FL.classifyWith f FL.sum)
173173
174174{-# INLINE unzip #-}
175175unzip :: Monad m => SerialT m Int -> m (Int, Int)
176−unzip = IP.fold $ FL.map (\a -> (a, a)) (FL.unzip FL.sum FL.length)
176+unzip = IP.fold $ FL.lmap (\a -> (a, a)) (FL.unzip FL.sum FL.length)
177177
178178-------------------------------------------------------------------------------
179179-- Benchmarks
@@ -228,7 +228,7 @@ o_1_space_serial_elimination value =
228228 , benchIOSink
229229 value
230230 "lookup"
231− (S.fold (FL.map (\a -> (a, a)) (FL.lookup (value + 1))))
231+ (S.fold (FL.lmap (\a -> (a, a)) (FL.lookup (value + 1))))
232232 , benchIOSink
233233 value
234234 "findIndex"
@@ -252,7 +252,7 @@ o_1_space_serial_elimination value =
252252o_1_space_serial_transformation :: Int -> [Benchmark]
253253o_1_space_serial_transformation value =
254254 [ bgroup "transformation"
255− [ benchIOSink value "map" (S.fold (FL.map (+ 1) FL.drain))
255+ [ benchIOSink value "map" (S.fold (FL.lmap (+ 1) FL.drain))
256256 , let f x = if even x then Just x else Nothing
257257 fld = FL.mapMaybe f FL.drain
258258 in benchIOSink value "mapMaybe" (S.fold fld)
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+1−1
@@ -211,7 +211,7 @@ packArraysChunksOf n str =
211211lpackArraysChunksOf :: (MonadIO m, Storable a)
212212 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
213213lpackArraysChunksOf n fld =
214− FL.map A.unsafeThaw $ AS.lpackArraysChunksOf n (FL.map A.unsafeFreeze fld)
214+ FL.lmap A.unsafeThaw $ AS.lpackArraysChunksOf n (FL.lmap A.unsafeFreeze fld)
215215
216216-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
217217-- maximum specified size in bytes.
src/Streamly/Internal/Data/Fold.hs+4−5
@@ -109,7 +109,6 @@ module Streamly.Internal.Data.Fold
109109
110110 -- ** Mapping on Input
111111 , transform
112− , map
113112 , lmap
114113 --, lsequence
115114 , lmapM
@@ -328,7 +327,7 @@ mapM = rmapM
328327-- @since 0.8.0
329328{-# INLINE mapMaybe #-}
330329mapMaybe :: (Monad m) => (a -> Maybe b) -> Fold m b r -> Fold m a r
331−mapMaybe f = map f . filter isJust . map fromJust
330+mapMaybe f = lmap f . filter isJust . lmap fromJust
332331
333332------------------------------------------------------------------------------
334333-- Transformations on fold inputs
@@ -1550,12 +1549,12 @@ classifyWith f (Fold step1 initial1 extract1) =
15501549--
15511550-- Same as:
15521551--
1553−-- > classify fld = Fold.classifyWith fst (map snd fld)
1552+-- > classify fld = Fold.classifyWith fst (lmap snd fld)
15541553--
15551554-- /Pre-release/
15561555{-# INLINE classify #-}
15571556classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
1558−classify fld = classifyWith fst (map snd fld)
1557+classify fld = classifyWith fst (lmap snd fld)
15591558
15601559------------------------------------------------------------------------------
15611560-- Unzipping
@@ -1719,7 +1718,7 @@ with ::
17191718 (Fold m (s, a) b -> Fold m a b)
17201719 -> (((s, a) -> c) -> Fold m (s, a) b -> Fold m (s, a) b)
17211720 -> (((s, a) -> c) -> Fold m a b -> Fold m a b)
1722−with f comb g = f . comb g . map snd
1721+with f comb g = f . comb g . lmap snd
17231722
17241723-- | @sampleFromthen offset stride@ samples the element at @offset@ index and
17251724-- then every element at strides of @stride@.
src/Streamly/Internal/Data/Fold/Type.hs+1−9
@@ -218,7 +218,6 @@ module Streamly.Internal.Data.Fold.Type
218218 , rmapM
219219
220220 -- ** Mapping Input
221− , map
222221 , lmap
223222 , lmapM
224223
@@ -917,13 +916,6 @@ lmap f (Fold step begin done) = Fold step' begin done
917916 where
918917 step' x a = step x (f a)
919918
920−-- XXX should be removed
921−-- |
922−-- /Internal/
923−{-# INLINE map #-}
924−map :: (a -> b) -> Fold m b r -> Fold m a r
925−map = lmap
926−
927919-- | @lmapM f fold@ maps the monadic function @f@ on the input of the fold.
928920--
929921-- @since 0.8.0
@@ -968,7 +960,7 @@ filterM f (Fold step begin done) = Fold step' begin done
968960-- @since 0.8.0
969961{-# INLINE catMaybes #-}
970962catMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
971−catMaybes = filter isJust . map fromJust
963+catMaybes = filter isJust . lmap fromJust
972964
973965------------------------------------------------------------------------------
974966-- Parsing