on master help sign in
Rename Fold.lmap to Fold.map
32e519cAdithya Kumar
benchmark/Streamly/Benchmark/Data/Fold.hs+5−5
@@ -129,7 +129,7 @@ partition =
129 if odd a
129 if odd a
130 then Left a
130 then Left a
131 else Right a
131 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)
133
133
134{-# INLINE demuxWith #-}
134{-# INLINE demuxWith #-}
135demuxWith ::
135demuxWith ::
@@ -147,7 +147,7 @@ demuxDefaultWith ::
147 -> Map k (Fold m b b)
147 -> Map k (Fold m b b)
148 -> SerialT m a
148 -> SerialT m a
149 -> m (Map k b, b)
149 -> 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))
151
151
152{-# INLINE classifyWith #-}
152{-# INLINE classifyWith #-}
153classifyWith ::
153classifyWith ::
@@ -160,7 +160,7 @@ classifyWith f = S.fold (FL.classifyWith f FL.sum)
160
160
161{-# INLINE unzip #-}
161{-# INLINE unzip #-}
162unzip :: Monad m => SerialT m Int -> m (Int, Int)
162unzip :: 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)
164
164
165-------------------------------------------------------------------------------
165-------------------------------------------------------------------------------
166-- Benchmarks
166-- Benchmarks
@@ -215,7 +215,7 @@ o_1_space_serial_elimination value =
215 , benchIOSink
215 , benchIOSink
216 value
216 value
217 "lookup"
217 "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))))
219 , benchIOSink
219 , benchIOSink
220 value
220 value
221 "findIndex"
221 "findIndex"
@@ -239,7 +239,7 @@ o_1_space_serial_elimination value =
239o_1_space_serial_transformation :: Int -> [Benchmark]
239o_1_space_serial_transformation :: Int -> [Benchmark]
240o_1_space_serial_transformation value =
240o_1_space_serial_transformation value =
241 [ bgroup "transformation"
241 [ bgroup "transformation"
242− [ benchIOSink value "lmap" (S.fold (FL.lmap (+ 1) FL.drain))
242+ [ benchIOSink value "map" (S.fold (FL.map (+ 1) FL.drain))
243 , let f x = if even x then Just x else Nothing
243 , let f x = if even x then Just x else Nothing
244 fld = FL.mapMaybe f FL.drain
244 fld = FL.mapMaybe f FL.drain
245 in benchIOSink value "mapMaybe" (S.fold fld)
245 in benchIOSink value "mapMaybe" (S.fold fld)
benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1
@@ -116,7 +116,7 @@ linesUnlinesArrayUtf8Copy inh outh =
116 S.fold (FH.write outh)
116 S.fold (FH.write outh)
117 $ SS.encodeLatin1'
117 $ SS.encodeLatin1'
118 $ IP.intercalate (A.fromList [10]) (pipe SS.decodeUtf8P A.read)
118 $ 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)
120 $ SS.decodeLatin1
120 $ SS.decodeLatin1
121 $ S.unfold FH.read inh
121 $ S.unfold FH.read inh
122-}
122-}
src/Streamly/Internal/Data/Array/Storable/Foreign/Types.hs+3−2
@@ -97,7 +97,7 @@ import GHC.ForeignPtr (touchForeignPtr, unsafeForeignPtrToPtr)
97#endif
97#endif
98import GHC.IO (unsafePerformIO)
98import GHC.IO (unsafePerformIO)
99import GHC.Ptr (Ptr(..))
99import GHC.Ptr (Ptr(..))
100−import Streamly.Internal.Data.Fold.Types (Fold(..), lmap)
100+import Streamly.Internal.Data.Fold.Types (Fold(..))
101import Text.Read (readPrec, readListPrec, readListPrecDefault)
101import Text.Read (readPrec, readListPrec, readListPrecDefault)
102
102
103import Prelude hiding (length, foldr, read, unlines, splitAt)
103import Prelude hiding (length, foldr, read, unlines, splitAt)
@@ -105,6 +105,7 @@ import Prelude hiding (length, foldr, read, unlines, splitAt)
105import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
105import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
106import qualified Streamly.Internal.Data.Stream.StreamK as K
106import qualified Streamly.Internal.Data.Stream.StreamK as K
107import qualified Streamly.Internal.Data.Array.Storable.Foreign.Mut.Types as MA
107import qualified Streamly.Internal.Data.Array.Storable.Foreign.Mut.Types as MA
108+import qualified Streamly.Internal.Data.Fold.Types as Fold
108import qualified GHC.Exts as Exts
109import qualified GHC.Exts as Exts
109
110
110#if __GLASGOW_HASKELL__ < 808
111#if __GLASGOW_HASKELL__ < 808
@@ -377,7 +378,7 @@ packArraysChunksOf n str =
377lpackArraysChunksOf :: (MonadIO m, Storable a)
378lpackArraysChunksOf :: (MonadIO m, Storable a)
378 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
379 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
379lpackArraysChunksOf n fld =
380lpackArraysChunksOf n fld =
380− lmap unsafeThaw $ MA.lpackArraysChunksOf n (lmap unsafeFreeze fld)
381+ Fold.map unsafeThaw $ MA.lpackArraysChunksOf n (Fold.map unsafeFreeze fld)
381
382
382#if !defined(mingw32_HOST_OS)
383#if !defined(mingw32_HOST_OS)
383
384
src/Streamly/Internal/Data/Fold.hs+9−9
@@ -107,7 +107,7 @@ module Streamly.Internal.Data.Fold
107
107
108 -- ** Mapping
108 -- ** Mapping
109 , transform
109 , transform
110− , lmap
110+ , map
111 --, lsequence
111 --, lsequence
112 , lmapM
112 , lmapM
113 -- ** Filtering
113 -- ** Filtering
@@ -403,7 +403,7 @@ mapM f = sequence . fmap f
403-- /Internal/
403-- /Internal/
404{-# INLINE mapMaybe #-}
404{-# INLINE mapMaybe #-}
405mapMaybe :: (Monad m) => (a -> Maybe b) -> Fold m b r -> Fold m a r
405mapMaybe :: (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
407
407
408------------------------------------------------------------------------------
408------------------------------------------------------------------------------
409-- Transformations on fold inputs
409-- Transformations on fold inputs
@@ -750,7 +750,7 @@ mconcat ::
750mconcat = sconcat mempty
750mconcat = sconcat mempty
751
751
752-- |
752-- |
753−-- > foldMap f = lmap f mconcat
753+-- > foldMap f = map f mconcat
754--
754--
755-- Make a fold from a pure function that folds the output of the function
755-- Make a fold from a pure function that folds the output of the function
756-- using 'mappend' and 'mempty'.
756-- using 'mappend' and 'mempty'.
@@ -764,7 +764,7 @@ foldMap :: (Monad m, Monoid b
764 , Semigroup b
764 , Semigroup b
765#endif
765#endif
766 ) => (a -> b) -> Fold m a b
766 ) => (a -> b) -> Fold m a b
767−foldMap f = lmap f mconcat
767+foldMap f = map f mconcat
768
768
769-- |
769-- |
770-- > foldMapM f = lmapM f mconcat
770-- > foldMapM f = lmapM f mconcat
@@ -935,7 +935,7 @@ null :: Monad m => Fold m a Bool
935null = mkFold (\() _ -> Done False) (Partial ()) (const True)
935null = mkFold (\() _ -> Done False) (Partial ()) (const True)
936
936
937--
937--
938−-- > any p = lmap p or
938+-- > any p = map p or
939-- > any p = fmap getAny . FL.foldMap (Any . p)
939-- > any p = fmap getAny . FL.foldMap (Any . p)
940--
940--
941-- | Returns 'True' if any of the elements of a stream satisfies a predicate.
941-- | 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
967elem a = any (a ==)
967elem a = any (a ==)
968
968
969--
969--
970−-- > all p = lmap p and
970+-- > all p = map p and
971-- > all p = fmap getAll . FL.foldMap (All . p)
971-- > all p = fmap getAll . FL.foldMap (All . p)
972--
972--
973-- | Returns 'True' if all elements of a stream satisfy a predicate.
973-- | 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
1992
1992
1993-- Same as:
1993-- Same as:
1994--
1994--
1995−-- > classify fld = classifyWith fst (lmap snd fld)
1995+-- > classify fld = classifyWith fst (map snd fld)
1996--
1996--
1997{-# INLINE classify #-}
1997{-# INLINE classify #-}
1998classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
1998classify :: (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)
2000
2000
2001------------------------------------------------------------------------------
2001------------------------------------------------------------------------------
2002-- Unzipping
2002-- Unzipping
@@ -2086,7 +2086,7 @@ unzipWithMinM = undefined
2086-- | Split elements in the input stream into two parts using a pure splitter
2086-- | Split elements in the input stream into two parts using a pure splitter
2087-- function, direct each part to a different fold and zip the results.
2087-- function, direct each part to a different fold and zip the results.
2088--
2088--
2089−-- @unzipWith f fld1 fld2 = lmap f (unzip fld1 fld2)@
2089+-- @unzipWith f fld1 fld2 = map f (unzip fld1 fld2)@
2090--
2090--
2091-- This fold terminates when both the input folds terminate.
2091-- This fold terminates when both the input folds terminate.
2092--
2092--
src/Streamly/Internal/Data/Fold/Types.hs+11−8
@@ -179,7 +179,7 @@ module Streamly.Internal.Data.Fold.Types
179 , yieldM
179 , yieldM
180
180
181 -- * Transformations
181 -- * Transformations
182− , lmap
182+ , map
183 , lmapM
183 , lmapM
184 , filter
184 , filter
185 , filterM
185 , filterM
@@ -230,7 +230,7 @@ import Fusion.Plugin.Types (Fuse(..))
230import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
230import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
231import Streamly.Internal.Data.SVar (MonadAsync)
231import Streamly.Internal.Data.SVar (MonadAsync)
232
232
233−import Prelude hiding (concatMap, filter)
233+import Prelude hiding (concatMap, filter, map)
234
234
235------------------------------------------------------------------------------
235------------------------------------------------------------------------------
236-- Monadic left folds
236-- Monadic left folds
@@ -644,15 +644,18 @@ instance (Monad m, Floating b) => Floating (Fold m a b) where
644-- Internal APIs
644-- Internal APIs
645------------------------------------------------------------------------------
645------------------------------------------------------------------------------
646
646
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.
648--
648--
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)
650-- 338350
650-- 338350
651--
651--
652+-- __Note__: This is not the same as 'fmap'. @map@ is contravariant where as
653+-- @fmap@ is covariant.
654+--
652-- @since 0.7.0
655-- @since 0.7.0
653−{-# INLINABLE lmap #-}
656+{-# INLINABLE map #-}
654−lmap :: (a -> b) -> Fold m b r -> Fold m a r
657+map :: (a -> b) -> Fold m b r -> Fold m a r
655−lmap f (Fold step begin done) = Fold step' begin done
658+map f (Fold step begin done) = Fold step' begin done
656 where
659 where
657 step' x a = step x (f a)
660 step' x a = step x (f a)
658
661
@@ -696,7 +699,7 @@ filterM f (Fold step begin done) = Fold step' begin done
696-- 'Just' values.
699-- 'Just' values.
697{-# INLINE lcatMaybes #-}
700{-# INLINE lcatMaybes #-}
698lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
701lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
699−lcatMaybes = filter isJust . lmap fromJust
702+lcatMaybes = filter isJust . map fromJust
700
703
701------------------------------------------------------------------------------
704------------------------------------------------------------------------------
702-- Parsing
705-- Parsing