@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wno-deprecations #-}
1{-# OPTIONS_GHC -Wno-deprecations #-}
2+{-# Language TypeApplications #-}
4-- Module : Streamly.Test.Prelude.Serial
5-- Module : Streamly.Test.Prelude.Serial
@@ -48,8 +49,10 @@ import qualified Streamly.Data.Stream.Prelude as S
48import qualified Streamly.Internal.Data.Fold as FL
49import qualified Streamly.Internal.Data.Fold as FL
49import qualified Streamly.Internal.Data.Unfold as UF
50import qualified Streamly.Internal.Data.Unfold as UF
50import qualified Streamly.Internal.Data.Stream as IS
51import qualified Streamly.Internal.Data.Stream as IS
52+import qualified Streamly.Internal.Data.Stream.StreamK as K
51import qualified Streamly.Data.Array as A
53import qualified Streamly.Data.Array as A
52import qualified Streamly.Internal.Data.Parser as Parser
54import qualified Streamly.Internal.Data.Parser as Parser
55+import qualified Streamly.Prelude as SP
54import Streamly.Internal.Data.Time.Units
57import Streamly.Internal.Data.Time.Units
55 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
58 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
@@ -90,8 +93,8 @@ groupsByRolling :: Monad m =>
90groupsByRolling cmp f m =
93groupsByRolling cmp f m =
91 S.catRights $ S.parseMany (Parser.groupByRolling cmp f) m
94 S.catRights $ S.parseMany (Parser.groupByRolling cmp f) m
93−drainWhile :: Monad m => (a -> Bool) -> S.Stream m a -> m ()
96+drainWhile :: Monad m => (a -> Bool) -> SerialT m a -> m ()
94−drainWhile p = S.fold FL.drain . S.takeWhile p
97+drainWhile p m = SP.fold FL.drain $ SP.takeWhile p m
96drainMapM :: Monad m => (a -> m b) -> S.Stream m a -> m ()
99drainMapM :: Monad m => (a -> m b) -> S.Stream m a -> m ()
97drainMapM f = S.fold (FL.drainMapM f)
100drainMapM f = S.fold (FL.drainMapM f)
@@ -427,12 +430,12 @@ associativityCheck desc t = prop desc assocCheckProp
427 assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
430 assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
428 assocCheckProp xs ys zs =
431 assocCheckProp xs ys zs =
429 monadicIO $ do
432 monadicIO $ do
430− let xStream = S.fromList xs
433+ let xStream = SP.fromList xs
431− yStream = S.fromList ys
434+ yStream = SP.fromList ys
432− zStream = S.fromList zs
435+ zStream = SP.fromList zs
433 infixAssocstream <-
436 infixAssocstream <-
434− run $ toList $ t $ xStream `serial` yStream `serial` zStream
437+ run $ SP.toList $ t $ xStream `serial` yStream `serial` zStream
435− assocStream <- run $ toList $ t $ xStream <> yStream <> zStream
438+ assocStream <- run $ SP.toList $ t $ xStream <> yStream <> zStream
436 listEquals (==) infixAssocstream assocStream
439 listEquals (==) infixAssocstream assocStream
438max_length :: Int
441max_length :: Int
@@ -540,7 +543,7 @@ foldIterateM =
540sortBy :: Property
543sortBy :: Property
541sortBy = forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
544sortBy = forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
542 let s1 = sort lst
545 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)
544 assert $ s1 == s2
547 assert $ s1 == s2
546moduleName :: String
549moduleName :: String
@@ -560,15 +563,15 @@ main = hspec
560 <> [("maxBuffer -1", fromSerial . maxBuffer (-1))]
563 <> [("maxBuffer -1", fromSerial . maxBuffer (-1))]
562 let toListSerial :: SerialT IO a -> IO [a]
565 let toListSerial :: SerialT IO a -> IO [a]
563− toListSerial = toList . fromSerial
566+ toListSerial = SP.toList
565 describe "Runners" $ do
568 describe "Runners" $ do
566 -- XXX use an IORef to store and check the side effects
569 -- XXX use an IORef to store and check the side effects
567 it "simple serially" $
570 it "simple serially" $
568− (S.fold FL.drain . fromSerial)
571+ (SP.fold FL.drain . fromSerial)
569 (return (0 :: Int)) `shouldReturn` ()
572 (return (0 :: Int)) `shouldReturn` ()
570 it "simple serially with IO" $
573 it "simple serially with IO" $
571− (S.fold FL.drain . fromSerial)
574+ (S.fold FL.drain)
572 (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
575 (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
574 describe "Empty" $
577 describe "Empty" $
@@ -601,8 +604,8 @@ main = hspec
601 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
604 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
602 serialOps $ prop "serially fromPure" . constructWithFromPure id
605 serialOps $ prop "serially fromPure" . constructWithFromPure id
603 serialOps $ prop "serially fromEffect" . constructWithFromEffect id
606 serialOps $ prop "serially fromEffect" . constructWithFromEffect id
604− serialOps $ prop "serially cons" . constructWithCons S.cons
607+ serialOps $ prop "serially cons" . constructWithCons SP.cons
605− serialOps $ prop "serially consM" . constructWithConsM S.consM id
608+ serialOps $ prop "serially consM" . constructWithConsM SP.consM id
607 describe "From Generators" $ do
610 describe "From Generators" $ do
608 prop "unfold" unfold
611 prop "unfold" unfold
@@ -610,7 +613,7 @@ main = hspec
610 describe "Simple Operations" $ serialOps simpleOps
613 describe "Simple Operations" $ serialOps simpleOps
612 describe "Functor operations" $ do
615 describe "Functor operations" $ do
613− serialOps $ functorOps S.fromFoldable "serially" (==)
616+ serialOps $ functorOps (SP.fromFoldable) "serially" (==)
614 serialOps $ functorOps folded "serially folded" (==)
617 serialOps $ functorOps folded "serially folded" (==)
616 describe "Monoid operations" $ do
619 describe "Monoid operations" $ do
@@ -639,17 +642,17 @@ main = hspec
639 -- The tests using sorted equality are weaker tests
642 -- The tests using sorted equality are weaker tests
640 -- We need to have stronger unit tests for all those
643 -- We need to have stronger unit tests for all those
641 -- XXX applicative with three arguments
644 -- XXX applicative with three arguments
642− serialOps $ applicativeOps S.fromFoldable "serially" (==)
645+ serialOps $ applicativeOps (SP.fromFoldable) "serially" (==)
643 serialOps $ applicativeOps folded "serially folded" (==)
646 serialOps $ applicativeOps folded "serially folded" (==)
644− serialOps $ applicativeOps1 S.fromFoldable "serially" (==)
647+ serialOps $ applicativeOps1 (SP.fromFoldable) "serially" (==)
645− serialOps $ applicativeOps1 S.fromFoldable "serially folded" (==)
648+ serialOps $ applicativeOps1 (SP.fromFoldable) "serially folded" (==)
647 -- XXX add tests for indexed/indexedR
650 -- XXX add tests for indexed/indexedR
648 describe "Zip operations" $ do
651 describe "Zip operations" $ do
649 -- We test only the serial zip with serial streams and the parallel
652 -- We test only the serial zip with serial streams and the parallel
650 -- stream, because the rate setting in these streams can slow down
653 -- stream, because the rate setting in these streams can slow down
651 -- zipAsync.
654 -- zipAsync.
652− serialOps $ prop "zip monadic serially" . zipMonadic S.fromFoldable (==)
655+ serialOps $ prop "zip monadic serially" . zipMonadic (SP.fromFoldable) (==)
653 serialOps $ prop "zip monadic serially folded" . zipMonadic folded (==)
656 serialOps $ prop "zip monadic serially folded" . zipMonadic folded (==)
655 -- XXX add merge tests like zip tests
658 -- XXX add merge tests like zip tests
@@ -658,15 +661,15 @@ main = hspec
658 -- describe "Merge operations" $ do
661 -- describe "Merge operations" $ do
660 describe "Monad operations" $ do
663 describe "Monad operations" $ do
661− serialOps $ prop "serially monad then" . monadThen S.fromFoldable (==)
664+ serialOps $ prop "serially monad then" . monadThen (SP.fromFoldable) (==)
662 serialOps $ prop "serially monad then folded" . monadThen folded (==)
665 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) (==)
664 serialOps $ prop "serially monad bind folded" . monadBind folded (==)
667 serialOps $ prop "serially monad bind folded" . monadBind folded (==)
666 describe "Stream transform and combine operations" $ do
669 describe "Stream transform and combine operations" $ do
667− serialOps $ transformCombineOpsCommon S.fromFoldable "serially" (==)
670+ serialOps $ transformCombineOpsCommon (SP.fromFoldable) "serially" (==)
668 serialOps $ transformCombineOpsCommon folded "serially" (==)
671 serialOps $ transformCombineOpsCommon folded "serially" (==)
669− serialOps $ transformCombineOpsOrdered S.fromFoldable "serially" (==)
672+ serialOps $ transformCombineOpsOrdered (SP.fromFoldable) "serially" (==)
670 serialOps $ transformCombineOpsOrdered folded "serially" (==)
673 serialOps $ transformCombineOpsOrdered folded "serially" (==)
672#ifdef DEVBUILD
675#ifdef DEVBUILD
@@ -678,19 +681,19 @@ main = hspec
678 -- Just some basic sanity tests for now
681 -- Just some basic sanity tests for now
679 let input = [[1,1] :: [Int],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]]
682 let input = [[1,1] :: [Int],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]]
680 mustBe g inp out =
683 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)))
682 `shouldReturn` out
685 `shouldReturn` out
684 it "concatPairsWith serial"
687 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]
686 it "concatPairsWith wSerial"
689 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]
688 it "concatPairsWith mergeBy sorted"
691 it "concatPairsWith mergeBy sorted"
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]
691 it "concatPairsWith mergeBy reversed"
694 it "concatPairsWith mergeBy reversed"
693− (S.mergeBy compare)
696+ (K.mergeBy compare)
694 (reverse input)
697 (reverse input)
695 [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
698 [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
696 prop "sortBy" sortBy
699 prop "sortBy" sortBy
@@ -699,9 +702,9 @@ main = hspec
699 groupSplitOps "serially"
702 groupSplitOps "serially"
701 describe "Stream elimination operations" $ do
704 describe "Stream elimination operations" $ do
702− serialOps $ eliminationOps S.fromFoldable "serially"
705+ serialOps $ eliminationOps (SP.fromFoldable) "serially"
703 serialOps $ eliminationOps folded "serially folded"
706 serialOps $ eliminationOps folded "serially folded"
704− serialOps $ eliminationOpsWord8 S.fromFoldable "serially"
707+ serialOps $ eliminationOpsWord8 (SP.fromFoldable) "serially"
705 serialOps $ eliminationOpsWord8 folded "serially folded"
708 serialOps $ eliminationOpsWord8 folded "serially folded"
706 serialOps $ \t ->
709 serialOps $ \t ->
707 prop "drainWhile (> 0)" $ \n ->
710 prop "drainWhile (> 0)" $ \n ->
@@ -711,15 +714,15 @@ main = hspec
711 ioRef <- run $ newIORef ([] :: [Int])
714 ioRef <- run $ newIORef ([] :: [Int])
713 drainWhile (> 0) . t $
716 drainWhile (> 0) . t $
714− S.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
717+ SP.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
715− S.fromList xs
718+ SP.fromList xs
716 strm <- run $ readIORef ioRef
719 strm <- run $ readIORef ioRef
717 listEquals (==) (reverse strm) (takeWhile (> 0) xs)
720 listEquals (==) (reverse strm) (takeWhile (> 0) xs)
719 -- XXX Add a test where we chain all transformation APIs and make sure that
722 -- XXX Add a test where we chain all transformation APIs and make sure that
720 -- the state is being passed through all of them.
723 -- the state is being passed through all of them.
721 describe "Stream serial elimination operations" $ do
724 describe "Stream serial elimination operations" $ do
722− serialOps $ eliminationOpsOrdered S.fromFoldable "serially"
725+ serialOps $ eliminationOpsOrdered (SP.fromFoldable) "serially"
723 serialOps $ eliminationOpsOrdered folded "serially folded"
726 serialOps $ eliminationOpsOrdered folded "serially folded"
725 describe "Tests for S.groupsBy" groupingOps
728 describe "Tests for S.groupsBy" groupingOps