on master help sign in
Rename Fold.lmap to Fold.map
commit32e519cb8cb25040bf384dfc51186ce61715c224 authorAdithya Kumar <adithya@composewell.com> dateFri 15 Jan 2021, 17:17 (6 years ago) parent528ce84
5 files changed+29−25
benchmark/Streamly/Benchmark/Data/Fold.hs+5−5 benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1 src/Streamly/Internal/Data/Array/Storable/Foreign/Types.hs+3−2 src/Streamly/Internal/Data/Fold.hs+9−9 src/Streamly/Internal/Data/Fold/Types.hs+11−8
benchmark/Streamly/Benchmark/Data/Fold.hs+5−5
@@ -129,7 +129,7 @@ partition =
129129 if odd a
130130 then Left a
131131 else Right a
132− in IP.fold $ FL.lmap f (FL.partition FL.sum FL.length)
132+ in IP.fold $ FL.map f (FL.partition FL.sum FL.length)
133133
134134{-# INLINE demuxWith #-}
135135demuxWith ::
@@ -147,7 +147,7 @@ demuxDefaultWith ::
147147 -> Map k (Fold m b b)
148148 -> SerialT m a
149149 -> m (Map k b, b)
150−demuxDefaultWith f mp = S.fold (FL.demuxDefaultWith f mp (FL.lmap snd FL.sum))
150+demuxDefaultWith f mp = S.fold (FL.demuxDefaultWith f mp (FL.map snd FL.sum))
151151
152152{-# INLINE classifyWith #-}
153153classifyWith ::
@@ -160,7 +160,7 @@ classifyWith f = S.fold (FL.classifyWith f FL.sum)
160160
161161{-# INLINE unzip #-}
162162unzip :: Monad m => SerialT m Int -> m (Int, Int)
163−unzip = IP.fold $ FL.lmap (\a -> (a, a)) (FL.unzip FL.sum FL.length)
163+unzip = IP.fold $ FL.map (\a -> (a, a)) (FL.unzip FL.sum FL.length)
164164
165165-------------------------------------------------------------------------------
166166-- Benchmarks
@@ -215,7 +215,7 @@ o_1_space_serial_elimination value =
215215 , benchIOSink
216216 value
217217 "lookup"
218− (S.fold (FL.lmap (\a -> (a, a)) (FL.lookup (value + 1))))
218+ (S.fold (FL.map (\a -> (a, a)) (FL.lookup (value + 1))))
219219 , benchIOSink
220220 value
221221 "findIndex"
@@ -239,7 +239,7 @@ o_1_space_serial_elimination value =
239239o_1_space_serial_transformation :: Int -> [Benchmark]
240240o_1_space_serial_transformation value =
241241 [ bgroup "transformation"
242− [ benchIOSink value "lmap" (S.fold (FL.lmap (+ 1) FL.drain))
242+ [ benchIOSink value "map" (S.fold (FL.map (+ 1) FL.drain))
243243 , let f x = if even x then Just x else Nothing
244244 fld = FL.mapMaybe f FL.drain
245245 in benchIOSink value "mapMaybe" (S.fold fld)
benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1
@@ -116,7 +116,7 @@ linesUnlinesArrayUtf8Copy inh outh =
116116 S.fold (FH.write outh)
117117 $ SS.encodeLatin1'
118118 $ IP.intercalate (A.fromList [10]) (pipe SS.decodeUtf8P A.read)
119− $ S.splitOnSuffix (== '\n') (IFL.lmap SS.encodeUtf8' A.write)
119+ $ S.splitOnSuffix (== '\n') (IFL.map SS.encodeUtf8' A.write)
120120 $ SS.decodeLatin1
121121 $ S.unfold FH.read inh
122122-}
src/Streamly/Internal/Data/Array/Storable/Foreign/Types.hs+3−2
@@ -97,7 +97,7 @@ import GHC.ForeignPtr (touchForeignPtr, unsafeForeignPtrToPtr)
9797#endif
9898import GHC.IO (unsafePerformIO)
9999import GHC.Ptr (Ptr(..))
100−import Streamly.Internal.Data.Fold.Types (Fold(..), lmap)
100+import Streamly.Internal.Data.Fold.Types (Fold(..))
101101import Text.Read (readPrec, readListPrec, readListPrecDefault)
102102
103103import Prelude hiding (length, foldr, read, unlines, splitAt)
@@ -105,6 +105,7 @@ import Prelude hiding (length, foldr, read, unlines, splitAt)
105105import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
106106import qualified Streamly.Internal.Data.Stream.StreamK as K
107107import qualified Streamly.Internal.Data.Array.Storable.Foreign.Mut.Types as MA
108+import qualified Streamly.Internal.Data.Fold.Types as Fold
108109import qualified GHC.Exts as Exts
109110
110111#if __GLASGOW_HASKELL__ < 808
@@ -377,7 +378,7 @@ packArraysChunksOf n str =
377378lpackArraysChunksOf :: (MonadIO m, Storable a)
378379 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
379380lpackArraysChunksOf n fld =
380− lmap unsafeThaw $ MA.lpackArraysChunksOf n (lmap unsafeFreeze fld)
381+ Fold.map unsafeThaw $ MA.lpackArraysChunksOf n (Fold.map unsafeFreeze fld)
381382
382383#if !defined(mingw32_HOST_OS)
383384
src/Streamly/Internal/Data/Fold.hs+9−9
@@ -107,7 +107,7 @@ module Streamly.Internal.Data.Fold
107107
108108 -- ** Mapping
109109 , transform
110− , lmap
110+ , map
111111 --, lsequence
112112 , lmapM
113113 -- ** Filtering
@@ -403,7 +403,7 @@ mapM f = sequence . fmap f
403403-- /Internal/
404404{-# INLINE mapMaybe #-}
405405mapMaybe :: (Monad m) => (a -> Maybe b) -> Fold m b r -> Fold m a r
406−mapMaybe f = lmap f . filter isJust . lmap fromJust
406+mapMaybe f = map f . filter isJust . map fromJust
407407
408408------------------------------------------------------------------------------
409409-- Transformations on fold inputs
@@ -750,7 +750,7 @@ mconcat ::
750750mconcat = sconcat mempty
751751
752752-- |
753−-- > foldMap f = lmap f mconcat
753+-- > foldMap f = map f mconcat
754754--
755755-- Make a fold from a pure function that folds the output of the function
756756-- using 'mappend' and 'mempty'.
@@ -764,7 +764,7 @@ foldMap :: (Monad m, Monoid b
764764 , Semigroup b
765765#endif
766766 ) => (a -> b) -> Fold m a b
767−foldMap f = lmap f mconcat
767+foldMap f = map f mconcat
768768
769769-- |
770770-- > foldMapM f = lmapM f mconcat
@@ -935,7 +935,7 @@ null :: Monad m => Fold m a Bool
935935null = mkFold (\() _ -> Done False) (Partial ()) (const True)
936936
937937--
938−-- > any p = lmap p or
938+-- > any p = map p or
939939-- > any p = fmap getAny . FL.foldMap (Any . p)
940940--
941941-- | Returns 'True' if any of the elements of a stream satisfies a predicate.
@@ -967,7 +967,7 @@ elem :: (Eq a, Monad m) => a -> Fold m a Bool
967967elem a = any (a ==)
968968
969969--
970−-- > all p = lmap p and
970+-- > all p = map p and
971971-- > all p = fmap getAll . FL.foldMap (All . p)
972972--
973973-- | Returns 'True' if all elements of a stream satisfy a predicate.
@@ -1992,11 +1992,11 @@ classifyWith f (Fold step1 initial1 extract1) = mkAccumM step initial extract
19921992
19931993-- Same as:
19941994--
1995−-- > classify fld = classifyWith fst (lmap snd fld)
1995+-- > classify fld = classifyWith fst (map snd fld)
19961996--
19971997{-# INLINE classify #-}
19981998classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
1999−classify fld = classifyWith fst (lmap snd fld)
1999+classify fld = classifyWith fst (map snd fld)
20002000
20012001------------------------------------------------------------------------------
20022002-- Unzipping
@@ -2086,7 +2086,7 @@ unzipWithMinM = undefined
20862086-- | Split elements in the input stream into two parts using a pure splitter
20872087-- function, direct each part to a different fold and zip the results.
20882088--
2089−-- @unzipWith f fld1 fld2 = lmap f (unzip fld1 fld2)@
2089+-- @unzipWith f fld1 fld2 = map f (unzip fld1 fld2)@
20902090--
20912091-- This fold terminates when both the input folds terminate.
20922092--
src/Streamly/Internal/Data/Fold/Types.hs+11−8
@@ -179,7 +179,7 @@ module Streamly.Internal.Data.Fold.Types
179179 , yieldM
180180
181181 -- * Transformations
182− , lmap
182+ , map
183183 , lmapM
184184 , filter
185185 , filterM
@@ -230,7 +230,7 @@ import Fusion.Plugin.Types (Fuse(..))
230230import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
231231import Streamly.Internal.Data.SVar (MonadAsync)
232232
233−import Prelude hiding (concatMap, filter)
233+import Prelude hiding (concatMap, filter, map)
234234
235235------------------------------------------------------------------------------
236236-- Monadic left folds
@@ -644,15 +644,18 @@ instance (Monad m, Floating b) => Floating (Fold m a b) where
644644-- Internal APIs
645645------------------------------------------------------------------------------
646646
647−-- | @(lmap f fold)@ maps the function @f@ on the input of the fold.
647+-- | @(map f fold)@ maps the function @f@ on the input of the fold.
648648--
649−-- >>> S.fold (FL.lmap (\x -> x * x) FL.sum) (S.enumerateFromTo 1 100)
649+-- >>> S.fold (FL.map (\x -> x * x) FL.sum) (S.enumerateFromTo 1 100)
650650-- 338350
651651--
652+-- __Note__: This is not the same as 'fmap'. @map@ is contravariant where as
653+-- @fmap@ is covariant.
654+--
652655-- @since 0.7.0
653−{-# INLINABLE lmap #-}
654−lmap :: (a -> b) -> Fold m b r -> Fold m a r
655−lmap f (Fold step begin done) = Fold step' begin done
656+{-# INLINABLE map #-}
657+map :: (a -> b) -> Fold m b r -> Fold m a r
658+map f (Fold step begin done) = Fold step' begin done
656659 where
657660 step' x a = step x (f a)
658661
@@ -696,7 +699,7 @@ filterM f (Fold step begin done) = Fold step' begin done
696699-- 'Just' values.
697700{-# INLINE lcatMaybes #-}
698701lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
699−lcatMaybes = filter isJust . lmap fromJust
702+lcatMaybes = filter isJust . map fromJust
700703
701704------------------------------------------------------------------------------
702705-- Parsing