on master help sign in
Deprecate mapM and sequence in favor of rmapM and rsequence
9473e6bAdithya Kumar
benchmark/Streamly/Benchmark/Data/Fold.hs+3−3
@@ -245,9 +245,9 @@ o_1_space_serial_transformation value =
245 in benchIOSink value "mapMaybe" (S.fold fld)
245 in benchIOSink value "mapMaybe" (S.fold fld)
246 , benchIOSink
246 , benchIOSink
247 value
247 value
248− "sequence"
248+ "rsequence"
249− (S.fold (FL.sequence (return <$> FL.drain)))
249+ (S.fold (FL.rsequence (return <$> FL.drain)))
250− , benchIOSink value "mapM" (S.fold (FL.mapM return FL.drain))
250+ , benchIOSink value "rmapM" (S.fold (FL.rmapM return FL.drain))
251 , benchIOSink
251 , benchIOSink
252 value
252 value
253 "pipe-mapM"
253 "pipe-mapM"
src/Streamly/Data/Fold.hs+2
@@ -128,7 +128,9 @@ module Streamly.Data.Fold
128 --
128 --
129 -- Note: Output transformations are also known as covariant
129 -- Note: Output transformations are also known as covariant
130 -- transformations.
130 -- transformations.
131+ , rsequence
131 , sequence
132 , sequence
133+ , rmapM
132 , mapM
134 , mapM
133
135
134 {-
136 {-
src/Streamly/Internal/Data/Array/Prim/TypesInclude.hs+3−3
@@ -162,7 +162,7 @@ nil =
162-- /Internal/
162-- /Internal/
163{-# INLINE_NORMAL write #-}
163{-# INLINE_NORMAL write #-}
164write :: (MonadIO m, Prim a) => Fold m a (Array a)
164write :: (MonadIO m, Prim a) => Fold m a (Array a)
165−write = FL.mapM unsafeFreeze MA.write
165+write = FL.rmapM unsafeFreeze MA.write
166
166
167-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
167-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
168-- 'Array'.
168-- 'Array'.
@@ -170,7 +170,7 @@ write = FL.mapM unsafeFreeze MA.write
170-- /Internal/
170-- /Internal/
171{-# INLINE_NORMAL writeN #-}
171{-# INLINE_NORMAL writeN #-}
172writeN :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
172writeN :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
173−writeN limit = FL.mapM unsafeFreeze (MA.writeN limit)
173+writeN limit = FL.rmapM unsafeFreeze (MA.writeN limit)
174
174
175-- | Like 'writeN' but does not check the array bounds when writing. The fold
175-- | Like 'writeN' but does not check the array bounds when writing. The fold
176-- driver must not call the step function more than 'n' times otherwise it will
176-- driver must not call the step function more than 'n' times otherwise it will
@@ -181,7 +181,7 @@ writeN limit = FL.mapM unsafeFreeze (MA.writeN limit)
181-- /Internal/
181-- /Internal/
182{-# INLINE_NORMAL writeNUnsafe #-}
182{-# INLINE_NORMAL writeNUnsafe #-}
183writeNUnsafe :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
183writeNUnsafe :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
184−writeNUnsafe limit = FL.mapM unsafeFreeze (MA.writeNUnsafe limit)
184+writeNUnsafe limit = FL.rmapM unsafeFreeze (MA.writeNUnsafe limit)
185
185
186{-# INLINE_NORMAL fromStreamDN #-}
186{-# INLINE_NORMAL fromStreamDN #-}
187fromStreamDN :: (MonadIO m, Prim a) => Int -> D.Stream m a -> m (Array a)
187fromStreamDN :: (MonadIO m, Prim a) => Int -> D.Stream m a -> m (Array a)
src/Streamly/Internal/Data/Array/Storable/Foreign/Mut/Types.hs+1−1
@@ -1177,7 +1177,7 @@ writeNUnsafe n = Fold step initial extract
1177{-# INLINE_NORMAL toArrayMinChunk #-}
1177{-# INLINE_NORMAL toArrayMinChunk #-}
1178toArrayMinChunk :: forall m a. (MonadIO m, Storable a)
1178toArrayMinChunk :: forall m a. (MonadIO m, Storable a)
1179 => Int -> Int -> Fold m a (Array a)
1179 => Int -> Int -> Fold m a (Array a)
1180−-- toArrayMinChunk n = FL.mapM spliceArrays $ toArraysOf n
1180+-- toArrayMinChunk n = FL.rmapM spliceArrays $ toArraysOf n
1181toArrayMinChunk alignSize elemCount = FL.mkAccumM step initial extract
1181toArrayMinChunk alignSize elemCount = FL.mkAccumM step initial extract
1182
1182
1183 where
1183 where
src/Streamly/Internal/Data/Array/Storable/Foreign/Types.hs+1−1
@@ -552,7 +552,7 @@ writeNUnsafe n = unsafeFreeze <$> MA.writeNUnsafe n
552{-# INLINE_NORMAL toArrayMinChunk #-}
552{-# INLINE_NORMAL toArrayMinChunk #-}
553toArrayMinChunk :: forall m a. (MonadIO m, Storable a)
553toArrayMinChunk :: forall m a. (MonadIO m, Storable a)
554 => Int -> Int -> Fold m a (Array a)
554 => Int -> Int -> Fold m a (Array a)
555−-- toArrayMinChunk n = FL.mapM spliceArrays $ toArraysOf n
555+-- toArrayMinChunk n = FL.rmapM spliceArrays $ toArraysOf n
556toArrayMinChunk alignSize elemCount =
556toArrayMinChunk alignSize elemCount =
557 unsafeFreeze <$> MA.toArrayMinChunk alignSize elemCount
557 unsafeFreeze <$> MA.toArrayMinChunk alignSize elemCount
558
558
src/Streamly/Internal/Data/Fold.hs+23−5
@@ -100,7 +100,9 @@ module Streamly.Internal.Data.Fold
100 , runStep
100 , runStep
101
101
102 -- * Output Transformations
102 -- * Output Transformations
103+ , rsequence
103 , sequence
104 , sequence
105+ , rmapM
104 , mapM
106 , mapM
105
107
106 -- * Input Transformations
108 -- * Input Transformations
@@ -366,10 +368,10 @@ generally = hoist (return . runIdentity)
366
368
367-- | Flatten the monadic output of a fold to pure output.
369-- | Flatten the monadic output of a fold to pure output.
368--
370--
369−-- @since 0.7.0
371+-- @since 0.8.0
370−{-# INLINE sequence #-}
372+{-# INLINE rsequence #-}
371−sequence :: Monad m => Fold m a (m b) -> Fold m a b
373+rsequence :: Monad m => Fold m a (m b) -> Fold m a b
372−sequence (Fold step initial extract) = Fold step' initial1 extract'
374+rsequence (Fold step initial extract) = Fold step' initial1 extract'
373
375
374 where
376 where
375
377
@@ -384,12 +386,28 @@ sequence (Fold step initial extract) = Fold step' initial1 extract'
384
386
385 extract' = join . extract
387 extract' = join . extract
386
388
389+-- | Flatten the monadic output of a fold to pure output.
390+--
391+-- @since 0.7.0
392+{-# DEPRECATED sequence "Use rsequence instead" #-}
393+{-# INLINE sequence #-}
394+sequence :: Monad m => Fold m a (m b) -> Fold m a b
395+sequence = rsequence
396+
397+-- | Map a monadic function on the output of a fold.
398+--
399+-- @since 0.8.0
400+{-# INLINE rmapM #-}
401+rmapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a c
402+rmapM f = sequence . fmap f
403+
387-- | Map a monadic function on the output of a fold.
404-- | Map a monadic function on the output of a fold.
388--
405--
389-- @since 0.7.0
406-- @since 0.7.0
407+{-# DEPRECATED mapM "Use rmapM instead" #-}
390{-# INLINE mapM #-}
408{-# INLINE mapM #-}
391mapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a c
409mapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a c
392−mapM f = sequence . fmap f
410+mapM = rmapM
393
411
394-- | @mapMaybe f fold@ maps a 'Maybe' returning function @f@ on the input of
412-- | @mapMaybe f fold@ maps a 'Maybe' returning function @f@ on the input of
395-- the fold, filters out 'Nothing' elements, and return the values extracted
413-- the fold, filters out 'Nothing' elements, and return the values extracted
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+1−1
@@ -372,7 +372,7 @@ tap f xs = D.fromStreamD $ D.tap f (D.toStreamD xs)
372-- this range then @offset `mod` n@ is used as offset.
372-- this range then @offset `mod` n@ is used as offset.
373--
373--
374-- @
374-- @
375−-- >>> S.drain $ S.tapOffsetEvery 0 2 (FL.mapM print FL.toList) $ S.enumerateFromTo 0 10
375+-- >>> S.drain $ S.tapOffsetEvery 0 2 (FL.rmapM print FL.toList) $ S.enumerateFromTo 0 10
376-- > [0,2,4,6,8,10]
376-- > [0,2,4,6,8,10]
377-- @
377-- @
378--
378--
test/Streamly/Test/Data/Fold.hs+4−4
@@ -343,8 +343,8 @@ lookup =
343 let v2 = Prelude.lookup key ls
343 let v2 = Prelude.lookup key ls
344 assert (v1 == v2)
344 assert (v1 == v2)
345
345
346−mapM :: Property
346+rmapM :: Property
347−mapM =
347+rmapM =
348 forAll (listOf1 (chooseInt (intMin, intMax)))
348 forAll (listOf1 (chooseInt (intMin, intMax)))
349 $ \ls0 -> monadicIO $ action ls0
349 $ \ls0 -> monadicIO $ action ls0
350
350
@@ -352,7 +352,7 @@ mapM =
352
352
353 action ls = do
353 action ls = do
354 let addLen x = return $ x + Prelude.length ls
354 let addLen x = return $ x + Prelude.length ls
355− fld = FL.mapM addLen FL.sum
355+ fld = FL.rmapM addLen FL.sum
356 v2 = foldl (+) (Prelude.length ls) ls
356 v2 = foldl (+) (Prelude.length ls) ls
357 v1 <- run $ S.fold fld $ S.fromList ls
357 v1 <- run $ S.fold fld $ S.fromList ls
358 assert (v1 == v2)
358 assert (v1 == v2)
@@ -455,7 +455,7 @@ main = hspec $
455 prop "foldMap" Main.foldMap
455 prop "foldMap" Main.foldMap
456 prop "foldMapM" Main.foldMapM
456 prop "foldMapM" Main.foldMapM
457 prop "lookup" Main.lookup
457 prop "lookup" Main.lookup
458− prop "mapM" Main.mapM
458+ prop "rmapM" Main.rmapM
459 prop "teeWithLength" Main.teeWithLength
459 prop "teeWithLength" Main.teeWithLength
460 prop "teeWithMax" Main.teeWithMax
460 prop "teeWithMax" Main.teeWithMax
461 prop "distribute" Main.distribute
461 prop "distribute" Main.distribute