on master help sign in
Move some functions from Streamly to Streamly.Prelude
f1670f3Harendra Kumar
Changelog.md+3
@@ -18,6 +18,9 @@
18 reason we no longer support this version of right fold. Please use `foldrM`
18 reason we no longer support this version of right fold. Please use `foldrM`
19 instead.
19 instead.
20
20
21+* `runStream`, `foldWith`, `foldMapWith`, `forEachWith` have been moved from
22+ "Streamly" module to "Streamly.Prelude" module.
23+
21## 0.6.1
24## 0.6.1
22
25
23### Bug Fixes
26### Bug Fixes
benchmark/Linear.hs+1−1
@@ -66,7 +66,7 @@ benchPureSinkIO name f =
66
66
67{-# INLINE benchPureSrc #-}
67{-# INLINE benchPureSrc #-}
68benchPureSrc :: String -> (Int -> SerialT Identity a) -> Benchmark
68benchPureSrc :: String -> (Int -> SerialT Identity a) -> Benchmark
69−benchPureSrc name src = benchPure name src (runIdentity . runStream)
69+benchPureSrc name src = benchPure name src (runIdentity . S.runStream)
70
70
71main :: IO ()
71main :: IO ()
72main =
72main =
benchmark/LinearOps.hs+1−1
@@ -27,7 +27,7 @@ import qualified GHC.Exts as GHC
27import Control.DeepSeq (NFData)
27import Control.DeepSeq (NFData)
28import GHC.Generics (Generic)
28import GHC.Generics (Generic)
29
29
30−import qualified Streamly as S
30+import qualified Streamly as S hiding (foldMapWith, runStream)
31import qualified Streamly.Prelude as S
31import qualified Streamly.Prelude as S
32
32
33value, maxValue :: Int
33value, maxValue :: Int
benchmark/NestedOps.hs+1−1
@@ -13,7 +13,7 @@ module NestedOps where
13import Control.Exception (try)
13import Control.Exception (try)
14import GHC.Exception (ErrorCall)
14import GHC.Exception (ErrorCall)
15
15
16−import qualified Streamly as S
16+import qualified Streamly as S hiding (runStream)
17import qualified Streamly.Prelude as S
17import qualified Streamly.Prelude as S
18
18
19sumCount :: Int
19sumCount :: Int
src/Streamly.hs+37−18
@@ -88,8 +88,6 @@ module Streamly
88 , ZipSerialM
88 , ZipSerialM
89 , ZipAsyncM
89 , ZipAsyncM
90
90
91− -- * Running Streams
92− , P.runStream
93 -- * Parallel Function Application
91 -- * Parallel Function Application
94 -- $application
92 -- $application
95 , (|$)
93 , (|$)
@@ -120,12 +118,6 @@ module Streamly
120 , maxRate
118 , maxRate
121 , constRate
119 , constRate
122
120
123− -- * Folding Containers of Streams
124− -- $foldutils
125− , foldWith
126− , foldMapWith
127− , forEachWith
128−
129 -- * Stream Type Adapters
121 -- * Stream Type Adapters
130 -- $adapters
122 -- $adapters
131 , IsStream ()
123 , IsStream ()
@@ -170,6 +162,13 @@ module Streamly
170 , zippingAsync
162 , zippingAsync
171 , (<=>)
163 , (<=>)
172 , (<|)
164 , (<|)
165+
166+ -- * Moved
167+ -- | These APIs have been moved to other modules
168+ , runStream
169+ , foldWith
170+ , foldMapWith
171+ , forEachWith
173 )
172 )
174where
173where
175
174
@@ -179,7 +178,6 @@ import Streamly.Streams.Ahead
179import Streamly.Streams.Async
178import Streamly.Streams.Async
180import Streamly.Streams.Combinators
179import Streamly.Streams.Combinators
181import Streamly.Streams.Parallel
180import Streamly.Streams.Parallel
182−import Streamly.Streams.Prelude
183import Streamly.Streams.Serial
181import Streamly.Streams.Serial
184import Streamly.Streams.StreamK hiding (runStream, serial)
182import Streamly.Streams.StreamK hiding (runStream, serial)
185import Streamly.Streams.Zip
183import Streamly.Streams.Zip
@@ -187,8 +185,6 @@ import Streamly.Streams.Zip
187import qualified Streamly.Prelude as P
185import qualified Streamly.Prelude as P
188import qualified Streamly.Streams.StreamK as K
186import qualified Streamly.Streams.StreamK as K
189
187
190−-- XXX This should perhaps be moved to Prelude.
191−
192------------------------------------------------------------------------------
188------------------------------------------------------------------------------
193-- Eliminating a stream
189-- Eliminating a stream
194------------------------------------------------------------------------------
190------------------------------------------------------------------------------
@@ -207,6 +203,12 @@ runStreaming = P.runStream . K.adapt
207runStreamT :: Monad m => SerialT m a -> m ()
203runStreamT :: Monad m => SerialT m a -> m ()
208runStreamT = P.runStream
204runStreamT = P.runStream
209
205
206+-- | Same as "Streamly.Prelude.runStream".
207+--
208+{-# DEPRECATED runStream "Please use Streamly.Prelude.runStream instead." #-}
209+runStream :: Monad m => SerialT m a -> m ()
210+runStream = P.runStream
211+
210-- | Same as @runStream . wSerially@.
212-- | Same as @runStream . wSerially@.
211--
213--
212-- @since 0.1.0
214-- @since 0.1.0
@@ -242,6 +244,30 @@ runZipStream = P.runStream . K.adapt
242runZipAsync :: Monad m => ZipAsyncM m a -> m ()
244runZipAsync :: Monad m => ZipAsyncM m a -> m ()
243runZipAsync = P.runStream . K.adapt
245runZipAsync = P.runStream . K.adapt
244
246
247+-- | Same as "Streamly.Prelude.foldWith".
248+--
249+{-# DEPRECATED foldWith "Please use Streamly.Prelude.foldWith instead." #-}
250+{-# INLINABLE foldWith #-}
251+foldWith :: (IsStream t, Foldable f)
252+ => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
253+foldWith = P.foldWith
254+
255+-- | Same as "Streamly.Prelude.foldMapWith".
256+--
257+{-# DEPRECATED foldMapWith "Please use Streamly.Prelude.foldMapWith instead." #-}
258+{-# INLINABLE foldMapWith #-}
259+foldMapWith :: (IsStream t, Foldable f)
260+ => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
261+foldMapWith = P.foldMapWith
262+
263+-- | Same as "Streamly.Prelude.forEachWith".
264+--
265+{-# DEPRECATED forEachWith "Please use Streamly.Prelude.forEachWith instead." #-}
266+{-# INLINABLE forEachWith #-}
267+forEachWith :: (IsStream t, Foldable f)
268+ => (t m b -> t m b -> t m b) -> f a -> (a -> t m b) -> t m b
269+forEachWith = P.forEachWith
270+
245------------------------------------------------------------------------------
271------------------------------------------------------------------------------
246-- Documentation
272-- Documentation
247------------------------------------------------------------------------------
273------------------------------------------------------------------------------
@@ -325,10 +351,3 @@ runZipAsync = P.runStream . K.adapt
325-- which specific type you are converting from or to. If you see a an
351-- which specific type you are converting from or to. If you see a an
326-- @ambiguous type variable@ error then most likely you are using 'adapt'
352-- @ambiguous type variable@ error then most likely you are using 'adapt'
327-- unnecessarily on polymorphic code.
353-- unnecessarily on polymorphic code.
328−--
329−
330−-- $foldutils
331−--
332−-- These are variants of standard 'Foldable' fold functions that use a
333−-- polymorphic stream sum operation (e.g. 'async' or 'wSerial') to fold a
334−-- container of streams.
src/Streamly/Prelude.hs+38−30
@@ -373,34 +373,6 @@ module Streamly.Prelude
373 -- ** Reordering
373 -- ** Reordering
374 , reverse
374 , reverse
375
375
376− -- ** Nested Producer Loops
377− -- | Map each element to a stream and then flatten the results into a
378− -- single stream. In imperative terms, a 'concatMap' corresponds to nested
379− -- loops. We loop over the outer stream and then for each element of the
380− -- outer stream an inner stream is generated and then we loop over the
381− -- inner stream as well to generate a single output stream.
382− --
383− -- @
384− --
385− -- ----Stream m a----|-Stream m b-|-Stream m b-|-...-|----Stream m b
386− --
387− -- @
388− --
389− -- 'concatMap' can perform filtering by mapping an element to a 'nil'
390− -- stream. Its a map, therefore it can degenerate to a simple map
391− -- operation as well:
392− --
393− -- > filter p m = S.concatMap (\x -> if p x then S.yield x else S.nil) m
394− -- > map f m = S.concatMap (\x -> S.yield (f x)) m
395− --
396− -- Though 'concatMap' is not inherently stateful, it can be combined with a
397− -- scan to perform stateful operations.
398−
399− , concatMapM
400− , concatMap
401− -- , interposeBy
402− -- , intercalate
403−
404 -- * Multi-Stream Operations
376 -- * Multi-Stream Operations
405 -- | New streams can be constructed by appending, merging or zipping
377 -- | New streams can be constructed by appending, merging or zipping
406 -- existing streams.
378 -- existing streams.
@@ -454,7 +426,25 @@ module Streamly.Prelude
454 , Z.zipAsyncWith
426 , Z.zipAsyncWith
455 , Z.zipAsyncWithM
427 , Z.zipAsyncWithM
456
428
457− -- ** Stream Level Folds
429+ -- ** Nested Streams
430+ -- | Stream operations represent loops in imperative programming, streams
431+ -- of streams represent nested loops.
432+
433+ , concatMapM
434+ , concatMap
435+ -- , interposeBy
436+ -- , intercalate
437+
438+ -- ** Containers of Streams
439+ -- | These are variants of standard 'Foldable' fold functions that use a
440+ -- polymorphic stream sum operation (e.g. 'async' or 'wSerial') to fold a
441+ -- finite container of streams.
442+ --
443+ , foldWith
444+ , foldMapWith
445+ , forEachWith
446+
447+ -- ** Folding
458 , eqBy
448 , eqBy
459 , cmpBy
449 , cmpBy
460 , isPrefixOf
450 , isPrefixOf
@@ -493,7 +483,8 @@ import Streamly.Enumeration (Enumerable(..), enumerate, enumerateTo)
493import Streamly.SVar (MonadAsync, defState)
483import Streamly.SVar (MonadAsync, defState)
494import Streamly.Streams.Async (mkAsync')
484import Streamly.Streams.Async (mkAsync')
495import Streamly.Streams.Combinators (maxYields)
485import Streamly.Streams.Combinators (maxYields)
496−import Streamly.Streams.Prelude (fromStreamS, toStreamS)
486+import Streamly.Streams.Prelude
487+ (fromStreamS, toStreamS, foldWith, foldMapWith, forEachWith)
497import Streamly.Streams.StreamD (fromStreamD, toStreamD)
488import Streamly.Streams.StreamD (fromStreamD, toStreamD)
498import Streamly.Streams.StreamK (IsStream(..))
489import Streamly.Streams.StreamK (IsStream(..))
499import Streamly.Streams.Serial (SerialT)
490import Streamly.Streams.Serial (SerialT)
@@ -2102,6 +2093,23 @@ mergeAsyncByM f m1 m2 = K.mkStream $ \st stp sng yld -> do
2102--
2093--
2103-- > concatMap f = concatMapM (return . f)
2094-- > concatMap f = concatMapM (return . f)
2104--
2095--
2096+-- In imperative terms, a 'concatMap' corresponds to nested loops. We loop over
2097+-- the input stream and then for each element of the input stream another
2098+-- stream is generated and then we loop over that inner stream as well to yield
2099+-- each element of that stream to generate a single output stream.
2100+--
2101+-- 'concatMap' can perform filtering by mapping an element to a 'nil'
2102+-- stream:
2103+--
2104+-- > filter p m = S.concatMap (\x -> if p x then S.yield x else S.nil) m
2105+--
2106+-- Its a map, therefore it can degenerate to a simple map operation as well:
2107+--
2108+-- > map f m = S.concatMap (\x -> S.yield (f x)) m
2109+--
2110+-- 'concatMap' is not inherently stateful, however, it can be combined with a
2111+-- scan to perform stateful operations.
2112+--
2105-- @since 0.6.0
2113-- @since 0.6.0
2106{-# INLINE concatMap #-}
2114{-# INLINE concatMap #-}
2107concatMap ::(IsStream t, Monad m) => (a -> t m b) -> t m a -> t m b
2115concatMap ::(IsStream t, Monad m) => (a -> t m b) -> t m a -> t m b
test/Main.hs+44−44
@@ -153,7 +153,7 @@ checkCleanup :: IsStream t
153 -> IO ()
153 -> IO ()
154checkCleanup d t op = do
154checkCleanup d t op = do
155 r <- newIORef (-1 :: Int)
155 r <- newIORef (-1 :: Int)
156− runStream . serially $ do
156+ S.runStream . serially $ do
157 _ <- t $ op $ delay r 0 S.|: delay r 1 S.|: delay r 2 S.|: S.nil
157 _ <- t $ op $ delay r 0 S.|: delay r 1 S.|: delay r 2 S.|: S.nil
158 return ()
158 return ()
159 performMajorGC
159 performMajorGC
@@ -193,9 +193,9 @@ parallelTests = H.parallel $ do
193 -- XXX move these to property tests
193 -- XXX move these to property tests
194 -- XXX use an IORef to store and check the side effects
194 -- XXX use an IORef to store and check the side effects
195 it "simple serially" $
195 it "simple serially" $
196− (runStream . serially) (return (0 :: Int)) `shouldReturn` ()
196+ (S.runStream . serially) (return (0 :: Int)) `shouldReturn` ()
197 it "simple serially with IO" $
197 it "simple serially with IO" $
198− (runStream . serially) (S.yieldM $ putStrLn "hello") `shouldReturn` ()
198+ (S.runStream . serially) (S.yieldM $ putStrLn "hello") `shouldReturn` ()
199
199
200 describe "Empty" $ -- do
200 describe "Empty" $ -- do
201 it "Monoid - mempty" $
201 it "Monoid - mempty" $
@@ -541,12 +541,12 @@ parallelTests = H.parallel $ do
541 ---------------------------------------------------------------------------
541 ---------------------------------------------------------------------------
542
542
543 it "asyncly crosses thread limit (2000 threads)" $
543 it "asyncly crosses thread limit (2000 threads)" $
544− runStream (asyncly $ fold $
544+ S.runStream (asyncly $ fold $
545 replicate 2000 $ S.yieldM $ threadDelay 1000000)
545 replicate 2000 $ S.yieldM $ threadDelay 1000000)
546 `shouldReturn` ()
546 `shouldReturn` ()
547
547
548 it "aheadly crosses thread limit (4000 threads)" $
548 it "aheadly crosses thread limit (4000 threads)" $
549− runStream (aheadly $ fold $
549+ S.runStream (aheadly $ fold $
550 replicate 4000 $ S.yieldM $ threadDelay 1000000)
550 replicate 4000 $ S.yieldM $ threadDelay 1000000)
551 `shouldReturn` ()
551 `shouldReturn` ()
552
552
@@ -596,7 +596,7 @@ monadicStateSnapshot
596 , MonadState Int (t (StateT Int IO))
596 , MonadState Int (t (StateT Int IO))
597 )
597 )
598 => (t (StateT Int IO) () -> SerialT (StateT Int IO) ()) -> IO ()
598 => (t (StateT Int IO) () -> SerialT (StateT Int IO) ()) -> IO ()
599−monadicStateSnapshot t = void $ runStateT (runStream $ t stateComp) 0
599+monadicStateSnapshot t = void $ runStateT (S.runStream $ t stateComp) 0
600
600
601stateCompOp
601stateCompOp
602 :: ( AsyncT (StateT Int IO) ()
602 :: ( AsyncT (StateT Int IO) ()
@@ -619,7 +619,7 @@ monadicStateSnapshotOp
619 -> AsyncT (StateT Int IO) ()
619 -> AsyncT (StateT Int IO) ()
620 )
620 )
621 -> IO ()
621 -> IO ()
622−monadicStateSnapshotOp op = void $ runStateT (runStream $ stateCompOp op) 0
622+monadicStateSnapshotOp op = void $ runStateT (S.runStream $ stateCompOp op) 0
623
623
624takeCombined :: (Monad m, Semigroup (t m Int), Show a, Eq a, IsStream t)
624takeCombined :: (Monad m, Semigroup (t m Int), Show a, Eq a, IsStream t)
625 => Int -> (t m Int -> SerialT IO a) -> IO ()
625 => Int -> (t m Int -> SerialT IO a) -> IO ()
@@ -669,7 +669,7 @@ checkScanxStrictness :: IO ()
669checkScanxStrictness = do
669checkScanxStrictness = do
670 let s = return (1 :: Int) `S.consM` error "failure"
670 let s = return (1 :: Int) `S.consM` error "failure"
671 catch
671 catch
672− (runStream (
672+ (S.runStream (
673 S.scanx (\_ a ->
673 S.scanx (\_ a ->
674 if a == 1
674 if a == 1
675 then error "success"
675 then error "success"
@@ -687,7 +687,7 @@ checkScanl'Strictness :: IO ()
687checkScanl'Strictness = do
687checkScanl'Strictness = do
688 let s = return (1 :: Int) `S.consM` error "failure"
688 let s = return (1 :: Int) `S.consM` error "failure"
689 catch
689 catch
690− (runStream
690+ (S.runStream
691 (S.scanl'
691 (S.scanl'
692 (\_ a ->
692 (\_ a ->
693 if a == 1
693 if a == 1
@@ -722,13 +722,13 @@ checkScanlMStrictness :: (IORef Int -> SerialT IO Int -> SerialT IO ()) -> IO ()
722checkScanlMStrictness f = do
722checkScanlMStrictness f = do
723 ref <- newIORef 0
723 ref <- newIORef 0
724 let s = return 1 `S.consM` error "x"
724 let s = return 1 `S.consM` error "x"
725− catch (runStream $ f ref s) (\(_ :: ErrorCall) -> return ())
725+ catch (S.runStream $ f ref s) (\(_ :: ErrorCall) -> return ())
726 readIORef ref `shouldReturn` 1
726 readIORef ref `shouldReturn` 1
727
727
728takeInfinite :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
728takeInfinite :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
729takeInfinite t =
729takeInfinite t =
730 it "take 1" $
730 it "take 1" $
731− runStream (t $ S.take 1 $ S.repeatM (print "hello" >> return (1::Int)))
731+ S.runStream (t $ S.take 1 $ S.repeatM (print "hello" >> return (1::Int)))
732 `shouldReturn` ()
732 `shouldReturn` ()
733
733
734-- XXX need to test that we have promptly cleaned up everything after the error
734-- XXX need to test that we have promptly cleaned up everything after the error
@@ -743,16 +743,16 @@ simpleMonadError :: Spec
743simpleMonadError = do
743simpleMonadError = do
744{-
744{-
745 it "simple runExceptT" $ do
745 it "simple runExceptT" $ do
746− (runExceptT $ runStream $ return ())
746+ (runExceptT $ S.runStream $ return ())
747 `shouldReturn` (Right () :: Either String ())
747 `shouldReturn` (Right () :: Either String ())
748 it "simple runExceptT with error" $ do
748 it "simple runExceptT with error" $ do
749− (runExceptT $ runStream $ throwError "E") `shouldReturn` Left "E"
749+ (runExceptT $ S.runStream $ throwError "E") `shouldReturn` Left "E"
750 -}
750 -}
751 it "simple try" $
751 it "simple try" $
752− try (runStream $ return ())
752+ try (S.runStream $ return ())
753 `shouldReturn` (Right () :: Either ExampleException ())
753 `shouldReturn` (Right () :: Either ExampleException ())
754 it "simple try with throw error" $
754 it "simple try with throw error" $
755− try (runStream $ throwM $ ExampleException "E")
755+ try (S.runStream $ throwM $ ExampleException "E")
756 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException ())
756 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException ())
757
757
758composeWithMonadThrow
758composeWithMonadThrow
@@ -790,8 +790,8 @@ composeWithMonadThrow t = do
790
790
791 oneLevelNestedProduct desc t1 =
791 oneLevelNestedProduct desc t1 =
792 it ("One level nested product" <> desc) $ do
792 it ("One level nested product" <> desc) $ do
793− let s1 = t $ foldMapWith (<>) return [1..4]
793+ let s1 = t $ S.foldMapWith (<>) return [1..4]
794− s2 = t1 $ foldMapWith (<>) return [5..8]
794+ s2 = t1 $ S.foldMapWith (<>) return [5..8]
795 try $ tl (do
795 try $ tl (do
796 x <- adapt s1
796 x <- adapt s1
797 y <- s2
797 y <- s2
@@ -816,8 +816,8 @@ _composeWithMonadError t = do
816
816
817nestTwoSerial :: Expectation
817nestTwoSerial :: Expectation
818nestTwoSerial =
818nestTwoSerial =
819− let s1 = foldMapWith (<>) return [1..4]
819+ let s1 = S.foldMapWith (<>) return [1..4]
820− s2 = foldMapWith (<>) return [5..8]
820+ s2 = S.foldMapWith (<>) return [5..8]
821 in toListSerial (do
821 in toListSerial (do
822 x <- s1
822 x <- s1
823 y <- s2
823 y <- s2
@@ -826,8 +826,8 @@ nestTwoSerial =
826
826
827nestTwoAhead :: Expectation
827nestTwoAhead :: Expectation
828nestTwoAhead =
828nestTwoAhead =
829− let s1 = foldMapWith (<>) return [1..4]
829+ let s1 = S.foldMapWith (<>) return [1..4]
830− s2 = foldMapWith (<>) return [5..8]
830+ s2 = S.foldMapWith (<>) return [5..8]
831 in (S.toList . aheadly) (do
831 in (S.toList . aheadly) (do
832 x <- s1
832 x <- s1
833 y <- s2
833 y <- s2
@@ -836,22 +836,22 @@ nestTwoAhead =
836
836
837nestTwoSerialApp :: Expectation
837nestTwoSerialApp :: Expectation
838nestTwoSerialApp =
838nestTwoSerialApp =
839− let s1 = foldMapWith (<>) return [1..4]
839+ let s1 = S.foldMapWith (<>) return [1..4]
840− s2 = foldMapWith (<>) return [5..8]
840+ s2 = S.foldMapWith (<>) return [5..8]
841 in toListSerial ((+) <$> s1 <*> s2)
841 in toListSerial ((+) <$> s1 <*> s2)
842 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
842 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
843
843
844nestTwoAheadApp :: Expectation
844nestTwoAheadApp :: Expectation
845nestTwoAheadApp =
845nestTwoAheadApp =
846− let s1 = foldMapWith (<>) return [1..4]
846+ let s1 = S.foldMapWith (<>) return [1..4]
847− s2 = foldMapWith (<>) return [5..8]
847+ s2 = S.foldMapWith (<>) return [5..8]
848 in (S.toList . aheadly) ((+) <$> s1 <*> s2)
848 in (S.toList . aheadly) ((+) <$> s1 <*> s2)
849 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
849 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
850
850
851nestTwoInterleaved :: Expectation
851nestTwoInterleaved :: Expectation
852nestTwoInterleaved =
852nestTwoInterleaved =
853− let s1 = foldMapWith (<>) return [1..4]
853+ let s1 = S.foldMapWith (<>) return [1..4]
854− s2 = foldMapWith (<>) return [5..8]
854+ s2 = S.foldMapWith (<>) return [5..8]
855 in toListInterleaved (do
855 in toListInterleaved (do
856 x <- s1
856 x <- s1
857 y <- s2
857 y <- s2
@@ -860,15 +860,15 @@ nestTwoInterleaved =
860
860
861nestTwoInterleavedApp :: Expectation
861nestTwoInterleavedApp :: Expectation
862nestTwoInterleavedApp =
862nestTwoInterleavedApp =
863− let s1 = foldMapWith (<>) return [1..4]
863+ let s1 = S.foldMapWith (<>) return [1..4]
864− s2 = foldMapWith (<>) return [5..8]
864+ s2 = S.foldMapWith (<>) return [5..8]
865 in toListInterleaved ((+) <$> s1 <*> s2)
865 in toListInterleaved ((+) <$> s1 <*> s2)
866 `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
866 `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
867
867
868nestTwoAsync :: Expectation
868nestTwoAsync :: Expectation
869nestTwoAsync =
869nestTwoAsync =
870− let s1 = foldMapWith (<>) return [1..4]
870+ let s1 = S.foldMapWith (<>) return [1..4]
871− s2 = foldMapWith (<>) return [5..8]
871+ s2 = S.foldMapWith (<>) return [5..8]
872 in sort <$> toListAsync (do
872 in sort <$> toListAsync (do
873 x <- s1
873 x <- s1
874 y <- s2
874 y <- s2
@@ -877,15 +877,15 @@ nestTwoAsync =
877
877
878nestTwoAsyncApp :: Expectation
878nestTwoAsyncApp :: Expectation
879nestTwoAsyncApp =
879nestTwoAsyncApp =
880− let s1 = foldMapWith (<>) return [1..4]
880+ let s1 = S.foldMapWith (<>) return [1..4]
881− s2 = foldMapWith (<>) return [5..8]
881+ s2 = S.foldMapWith (<>) return [5..8]
882 in sort <$> toListAsync ((+) <$> s1 <*> s2)
882 in sort <$> toListAsync ((+) <$> s1 <*> s2)
883 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
883 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
884
884
885nestTwoWAsync :: Expectation
885nestTwoWAsync :: Expectation
886nestTwoWAsync =
886nestTwoWAsync =
887− let s1 = foldMapWith (<>) return [1..4]
887+ let s1 = S.foldMapWith (<>) return [1..4]
888− s2 = foldMapWith (<>) return [5..8]
888+ s2 = S.foldMapWith (<>) return [5..8]
889 in sort <$> (S.toList . wAsyncly) (do
889 in sort <$> (S.toList . wAsyncly) (do
890 x <- s1
890 x <- s1
891 y <- s2
891 y <- s2
@@ -894,8 +894,8 @@ nestTwoWAsync =
894
894
895nestTwoParallel :: Expectation
895nestTwoParallel :: Expectation
896nestTwoParallel =
896nestTwoParallel =
897− let s1 = foldMapWith (<>) return [1..4]
897+ let s1 = S.foldMapWith (<>) return [1..4]
898− s2 = foldMapWith (<>) return [5..8]
898+ s2 = S.foldMapWith (<>) return [5..8]
899 in sort <$> (S.toList . parallely) (do
899 in sort <$> (S.toList . parallely) (do
900 x <- s1
900 x <- s1
901 y <- s2
901 y <- s2
@@ -904,15 +904,15 @@ nestTwoParallel =
904
904
905nestTwoWAsyncApp :: Expectation
905nestTwoWAsyncApp :: Expectation
906nestTwoWAsyncApp =
906nestTwoWAsyncApp =
907− let s1 = foldMapWith (<>) return [1..4]
907+ let s1 = S.foldMapWith (<>) return [1..4]
908− s2 = foldMapWith (<>) return [5..8]
908+ s2 = S.foldMapWith (<>) return [5..8]
909 in sort <$> (S.toList . wAsyncly) ((+) <$> s1 <*> s2)
909 in sort <$> (S.toList . wAsyncly) ((+) <$> s1 <*> s2)
910 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
910 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
911
911
912nestTwoParallelApp :: Expectation
912nestTwoParallelApp :: Expectation
913nestTwoParallelApp =
913nestTwoParallelApp =
914− let s1 = foldMapWith (<>) return [1..4]
914+ let s1 = S.foldMapWith (<>) return [1..4]
915− s2 = foldMapWith (<>) return [5..8]
915+ s2 = S.foldMapWith (<>) return [5..8]
916 in sort <$> (S.toList . parallely) ((+) <$> s1 <*> s2)
916 in sort <$> (S.toList . parallely) ((+) <$> s1 <*> s2)
917 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
917 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
918
918
@@ -954,7 +954,7 @@ compose t z srt = do
954 srt <$> tl (singleton 0 <> singleton 1)
954 srt <$> tl (singleton 0 <> singleton 1)
955 `shouldReturn` [0, 1]
955 `shouldReturn` [0, 1]
956 it "Compose many" $
956 it "Compose many" $
957− srt <$> tl (forEachWith (<>) [1..100] singleton)
957+ srt <$> tl (S.forEachWith (<>) [1..100] singleton)
958 `shouldReturn` [1..100]
958 `shouldReturn` [1..100]
959
959
960 -- These are not covered by the property tests
960 -- These are not covered by the property tests
@@ -984,7 +984,7 @@ composeAndComposeSimple
984 -> (t2 IO Int -> t2 IO Int)
984 -> (t2 IO Int -> t2 IO Int)
985 -> [[Int]] -> Spec
985 -> [[Int]] -> Spec
986composeAndComposeSimple t1 t2 answer = do
986composeAndComposeSimple t1 t2 answer = do
987− let rfold = adapt . t2 . foldMapWith (<>) return
987+ let rfold = adapt . t2 . S.foldMapWith (<>) return
988 it "Compose right associated outer expr, right folded inner" $
988 it "Compose right associated outer expr, right folded inner" $
989 (S.toList . t1) (rfold [1,2,3] <> (rfold [4,5,6] <> rfold [7,8,9]))
989 (S.toList . t1) (rfold [1,2,3] <> (rfold [4,5,6] <> rfold [7,8,9]))
990 `shouldReturn` head answer
990 `shouldReturn` head answer
@@ -1035,7 +1035,7 @@ bindAndComposeSimple t1 t2 = do
1035 -- XXX need a bind in the body of forEachWith instead of a simple return
1035 -- XXX need a bind in the body of forEachWith instead of a simple return
1036 it "Compose many (right fold) with bind" $
1036 it "Compose many (right fold) with bind" $
1037 (sort <$> (S.toList . t1)
1037 (sort <$> (S.toList . t1)
1038− (adapt . t2 $ forEachWith (<>) [1..10 :: Int] return))
1038+ (adapt . t2 $ S.forEachWith (<>) [1..10 :: Int] return))
1039 `shouldReturn` [1..10]
1039 `shouldReturn` [1..10]
1040
1040
1041 it "Compose many (left fold) with bind" $
1041 it "Compose many (left fold) with bind" $
test/Prop.hs+3−3
@@ -693,8 +693,8 @@ semigroupOps
693 -> (t IO Int -> SerialT IO Int)
693 -> (t IO Int -> SerialT IO Int)
694 -> Spec
694 -> Spec
695semigroupOps desc eq t = do
695semigroupOps desc eq t = do
696− prop (desc <> " <>") $ foldFromList (foldMapWith (<>) singleton) t eq
696+ prop (desc <> " <>") $ foldFromList (S.foldMapWith (<>) singleton) t eq
697− prop (desc <> " mappend") $ foldFromList (foldMapWith mappend singleton) t eq
697+ prop (desc <> " mappend") $ foldFromList (S.foldMapWith mappend singleton) t eq
698
698
699-------------------------------------------------------------------------------
699-------------------------------------------------------------------------------
700-- Functor operations
700-- Functor operations
@@ -829,7 +829,7 @@ main = hspec
829 folded = serially . (\xs ->
829 folded = serially . (\xs ->
830 case xs of
830 case xs of
831 [x] -> return x -- singleton stream case
831 [x] -> return x -- singleton stream case
832− _ -> foldMapWith (<>) return xs
832+ _ -> S.foldMapWith (<>) return xs
833 )
833 )
834
834
835 let makeOps t =
835 let makeOps t =
test/loops.hs+2−2
@@ -1,6 +1,6 @@
1−import Streamly
1+import Streamly hiding (runStream)
2import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
2import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
3−import Streamly.Prelude (nil, yieldM)
3+import Streamly.Prelude (nil, yieldM, runStream)
4
4
5main :: IO ()
5main :: IO ()
6main = do
6main = do
test/parallel-loops.hs+1−1
@@ -7,7 +7,7 @@ import qualified Streamly.Prelude as S
7main :: IO ()
7main :: IO ()
8main = do
8main = do
9 hSetBuffering stdout LineBuffering
9 hSetBuffering stdout LineBuffering
10− runStream $ do
10+ S.runStream $ do
11 x <- S.take 10 $ loop "A" `parallel` loop "B"
11 x <- S.take 10 $ loop "A" `parallel` loop "B"
12 S.yieldM $ myThreadId >>= putStr . show
12 S.yieldM $ myThreadId >>= putStr . show
13 >> putStr " got "
13 >> putStr " got "