@@ -1,4 +1,5 @@
11{-# OPTIONS_GHC -Wno-deprecations #-}
2+{-# Language TypeApplications #-}
23
34-- |
45-- Module : Streamly.Test.Prelude.Serial
@@ -48,8 +49,10 @@ import qualified Streamly.Data.Stream.Prelude as S
4849import qualified Streamly.Internal.Data.Fold as FL
4950import qualified Streamly.Internal.Data.Unfold as UF
5051import qualified Streamly.Internal.Data.Stream as IS
52+import qualified Streamly.Internal.Data.Stream.StreamK as K
5153import qualified Streamly.Data.Array as A
5254import qualified Streamly.Internal.Data.Parser as Parser
55+import qualified Streamly.Prelude as SP
5356
5457import Streamly.Internal.Data.Time.Units
5558 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
@@ -90,8 +93,8 @@ groupsByRolling :: Monad m =>
9093groupsByRolling cmp f m =
9194 S.catRights $ S.parseMany (Parser.groupByRolling cmp f) m
9295
93−drainWhile :: Monad m => (a -> Bool) -> S.Stream m a -> m ()
94−drainWhile p = S.fold FL.drain . S.takeWhile p
96+drainWhile :: Monad m => (a -> Bool) -> SerialT m a -> m ()
97+drainWhile p m = SP.fold FL.drain $ SP.takeWhile p m
9598
9699drainMapM :: Monad m => (a -> m b) -> S.Stream m a -> m ()
97100drainMapM f = S.fold (FL.drainMapM f)
@@ -427,12 +430,12 @@ associativityCheck desc t = prop desc assocCheckProp
427430 assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
428431 assocCheckProp xs ys zs =
429432 monadicIO $ do
430− let xStream = S.fromList xs
431− yStream = S.fromList ys
432− zStream = S.fromList zs
433+ let xStream = SP.fromList xs
434+ yStream = SP.fromList ys
435+ zStream = SP.fromList zs
433436 infixAssocstream <-
434− run $ toList $ t $ xStream `serial` yStream `serial` zStream
435− assocStream <- run $ toList $ t $ xStream <> yStream <> zStream
437+ run $ SP.toList $ t $ xStream `serial` yStream `serial` zStream
438+ assocStream <- run $ SP.toList $ t $ xStream <> yStream <> zStream
436439 listEquals (==) infixAssocstream assocStream
437440
438441max_length :: Int
@@ -540,7 +543,7 @@ foldIterateM =
540543sortBy :: Property
541544sortBy = forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
542545 let s1 = sort lst
543− s2 <- toList $ IS.sortBy compare $ S.fromList lst
546+ s2 <- toList $ K.toStream (K.sortBy compare $ K.fromStream $ S.fromList lst)
544547 assert $ s1 == s2
545548
546549moduleName :: String
@@ -560,15 +563,15 @@ main = hspec
560563 <> [("maxBuffer -1", fromSerial . maxBuffer (-1))]
561564#endif
562565 let toListSerial :: SerialT IO a -> IO [a]
563− toListSerial = toList . fromSerial
566+ toListSerial = SP.toList
564567
565568 describe "Runners" $ do
566569 -- XXX use an IORef to store and check the side effects
567570 it "simple serially" $
568− (S.fold FL.drain . fromSerial)
571+ (SP.fold FL.drain . fromSerial)
569572 (return (0 :: Int)) `shouldReturn` ()
570573 it "simple serially with IO" $
571− (S.fold FL.drain . fromSerial)
574+ (S.fold FL.drain)
572575 (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
573576
574577 describe "Empty" $
@@ -601,8 +604,8 @@ main = hspec
601604 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
602605 serialOps $ prop "serially fromPure" . constructWithFromPure id
603606 serialOps $ prop "serially fromEffect" . constructWithFromEffect id
604− serialOps $ prop "serially cons" . constructWithCons S.cons
605− serialOps $ prop "serially consM" . constructWithConsM S.consM id
607+ serialOps $ prop "serially cons" . constructWithCons SP.cons
608+ serialOps $ prop "serially consM" . constructWithConsM SP.consM id
606609
607610 describe "From Generators" $ do
608611 prop "unfold" unfold
@@ -610,7 +613,7 @@ main = hspec
610613 describe "Simple Operations" $ serialOps simpleOps
611614
612615 describe "Functor operations" $ do
613− serialOps $ functorOps S.fromFoldable "serially" (==)
616+ serialOps $ functorOps (SP.fromFoldable) "serially" (==)
614617 serialOps $ functorOps folded "serially folded" (==)
615618
616619 describe "Monoid operations" $ do
@@ -639,17 +642,17 @@ main = hspec
639642 -- The tests using sorted equality are weaker tests
640643 -- We need to have stronger unit tests for all those
641644 -- XXX applicative with three arguments
642− serialOps $ applicativeOps S.fromFoldable "serially" (==)
645+ serialOps $ applicativeOps (SP.fromFoldable) "serially" (==)
643646 serialOps $ applicativeOps folded "serially folded" (==)
644− serialOps $ applicativeOps1 S.fromFoldable "serially" (==)
645− serialOps $ applicativeOps1 S.fromFoldable "serially folded" (==)
647+ serialOps $ applicativeOps1 (SP.fromFoldable) "serially" (==)
648+ serialOps $ applicativeOps1 (SP.fromFoldable) "serially folded" (==)
646649
647650 -- XXX add tests for indexed/indexedR
648651 describe "Zip operations" $ do
649652 -- We test only the serial zip with serial streams and the parallel
650653 -- stream, because the rate setting in these streams can slow down
651654 -- zipAsync.
652− serialOps $ prop "zip monadic serially" . zipMonadic S.fromFoldable (==)
655+ serialOps $ prop "zip monadic serially" . zipMonadic (SP.fromFoldable) (==)
653656 serialOps $ prop "zip monadic serially folded" . zipMonadic folded (==)
654657
655658 -- XXX add merge tests like zip tests
@@ -658,15 +661,15 @@ main = hspec
658661 -- describe "Merge operations" $ do
659662
660663 describe "Monad operations" $ do
661− serialOps $ prop "serially monad then" . monadThen S.fromFoldable (==)
664+ serialOps $ prop "serially monad then" . monadThen (SP.fromFoldable) (==)
662665 serialOps $ prop "serially monad then folded" . monadThen folded (==)
663− serialOps $ prop "serially monad bind" . monadBind S.fromFoldable (==)
666+ serialOps $ prop "serially monad bind" . monadBind (SP.fromFoldable) (==)
664667 serialOps $ prop "serially monad bind folded" . monadBind folded (==)
665668
666669 describe "Stream transform and combine operations" $ do
667− serialOps $ transformCombineOpsCommon S.fromFoldable "serially" (==)
670+ serialOps $ transformCombineOpsCommon (SP.fromFoldable) "serially" (==)
668671 serialOps $ transformCombineOpsCommon folded "serially" (==)
669− serialOps $ transformCombineOpsOrdered S.fromFoldable "serially" (==)
672+ serialOps $ transformCombineOpsOrdered (SP.fromFoldable) "serially" (==)
670673 serialOps $ transformCombineOpsOrdered folded "serially" (==)
671674
672675#ifdef DEVBUILD
@@ -678,19 +681,19 @@ main = hspec
678681 -- Just some basic sanity tests for now
679682 let input = [[1,1] :: [Int],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]]
680683 mustBe g inp out =
681− toList (S.mergeMapWith g S.fromList (S.fromList inp))
684+ toList (K.toStream (K.mergeMapWith g K.fromList (K.fromList inp)))
682685 `shouldReturn` out
683686 in do
684687 it "concatPairsWith serial"
685− $ mustBe S.append input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
688+ $ mustBe K.append input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
686689 it "concatPairsWith wSerial"
687− $ mustBe S.interleave input [1,5,3,7,2,6,4,8,1,5,3,7,2,6,4,8]
690+ $ mustBe K.interleave input [1,5,3,7,2,6,4,8,1,5,3,7,2,6,4,8]
688691 it "concatPairsWith mergeBy sorted"
689692 $ mustBe
690− (S.mergeBy compare) input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
693+ (K.mergeBy compare) input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
691694 it "concatPairsWith mergeBy reversed"
692695 $ mustBe
693− (S.mergeBy compare)
696+ (K.mergeBy compare)
694697 (reverse input)
695698 [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
696699 prop "sortBy" sortBy
@@ -699,9 +702,9 @@ main = hspec
699702 groupSplitOps "serially"
700703
701704 describe "Stream elimination operations" $ do
702− serialOps $ eliminationOps S.fromFoldable "serially"
705+ serialOps $ eliminationOps (SP.fromFoldable) "serially"
703706 serialOps $ eliminationOps folded "serially folded"
704− serialOps $ eliminationOpsWord8 S.fromFoldable "serially"
707+ serialOps $ eliminationOpsWord8 (SP.fromFoldable) "serially"
705708 serialOps $ eliminationOpsWord8 folded "serially folded"
706709 serialOps $ \t ->
707710 prop "drainWhile (> 0)" $ \n ->
@@ -711,15 +714,15 @@ main = hspec
711714 ioRef <- run $ newIORef ([] :: [Int])
712715 run $
713716 drainWhile (> 0) . t $
714− S.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
715− S.fromList xs
717+ SP.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
718+ SP.fromList xs
716719 strm <- run $ readIORef ioRef
717720 listEquals (==) (reverse strm) (takeWhile (> 0) xs)
718721
719722 -- XXX Add a test where we chain all transformation APIs and make sure that
720723 -- the state is being passed through all of them.
721724 describe "Stream serial elimination operations" $ do
722− serialOps $ eliminationOpsOrdered S.fromFoldable "serially"
725+ serialOps $ eliminationOpsOrdered (SP.fromFoldable) "serially"
723726 serialOps $ eliminationOpsOrdered folded "serially folded"
724727
725728 describe "Tests for S.groupsBy" groupingOps