@@ -38,13 +38,15 @@ import qualified Data.Foldable as F
38import qualified GHC.Exts as GHC
38import qualified GHC.Exts as GHC
40#ifdef INSPECTION
40#ifdef INSPECTION
41−import Streamly.Streams.StreamD.Type (Step(..))
42import Test.Inspection
41import Test.Inspection
43+import qualified Streamly.Streams.StreamD as D
45import qualified Streamly as S hiding (foldMapWith, runStream)
46import qualified Streamly as S hiding (foldMapWith, runStream)
46import qualified Streamly.Prelude as S
47import qualified Streamly.Prelude as S
47import qualified Streamly.Internal as Internal
48import qualified Streamly.Internal as Internal
49+import qualified Streamly.Unfold as UF
48-- import qualified Streamly.Pipe as Pipe
50-- import qualified Streamly.Pipe as Pipe
50value, maxValue, value2 :: Int
52value, maxValue, value2 :: Int
@@ -132,6 +134,12 @@ sourceFoldMapM :: (S.IsStream t, Monad m, P.Monoid (t m Int))
132 => Int -> t m Int
134 => Int -> t m Int
133sourceFoldMapM n = F.foldMap (S.yieldM . return) [n..n+value]
135sourceFoldMapM n = F.foldMap (S.yieldM . return) [n..n+value]
137+{-# INLINE sourceConcatMapId #-}
138+sourceConcatMapId :: (S.IsStream t, Monad m)
140+sourceConcatMapId n =
141+ S.concatMap P.id $ S.fromFoldable $ P.map (S.yieldM . return) [n..n+value]
135{-# INLINE sourceUnfoldr #-}
143{-# INLINE sourceUnfoldr #-}
136sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> t m Int
144sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> t m Int
137sourceUnfoldr n = S.unfoldr step n
145sourceUnfoldr n = S.unfoldr step n
@@ -503,44 +511,105 @@ iterateDropWhileTrue = iterateSource (S.dropWhile (<= maxValue)) maxIters
503-------------------------------------------------------------------------------
511-------------------------------------------------------------------------------
505{-# INLINE zip #-}
513{-# INLINE zip #-}
506−zip :: Monad m => Stream m Int -> m ()
514+zip :: Int -> Int -> IO ()
507−zip src = do
515+zip count n =
509− let src1 = fromJust r
510− transform (S.zipWith (,) src src1)
516+ S.drain $ S.zipWith (,)
517+ (sourceUnfoldrMN count n)
518+ (sourceUnfoldrMN count (n + 1))
512−{-# INLINE zipM' #-}
520+#ifdef INSPECTION
513−zipM' :: Monad m => Stream m Int -> m ()
521+inspect $ hasNoTypeClasses 'zip
514−zipM' src = do
522+inspect $ 'zip `hasNoType` ''D.Step
515− r <- S.tail src
523+#endif
516− let src1 = fromJust r
517− transform (S.zipWithM (curry return) src src1)
519{-# INLINE zipM #-}
525{-# INLINE zipM #-}
520−zipM :: Int -> IO ()
526+zipM :: Int -> Int -> IO ()
521−zipM n = zipM' $ source n
527+zipM count n =
528+ S.drain $ S.zipWithM (curry return)
529+ (sourceUnfoldrMN count n)
530+ (sourceUnfoldrMN count (n + 1))
523#ifdef INSPECTION
532#ifdef INSPECTION
524inspect $ hasNoTypeClasses 'zipM
533inspect $ hasNoTypeClasses 'zipM
525−-- inspect $ 'zipM `hasNoType` ''Step
534+inspect $ 'zipM `hasNoType` ''D.Step
528−{-# INLINE mergeBy' #-}
529−mergeBy' :: Monad m => Stream m Int -> m ()
532− let src1 = fromJust r
533− transform (S.mergeBy P.compare src src1)
535{-# INLINE mergeBy #-}
537{-# INLINE mergeBy #-}
536−mergeBy :: Int -> IO ()
538+mergeBy :: Int -> Int -> IO ()
537−mergeBy n = mergeBy' $ source n
539+mergeBy count n =
540+ S.drain $ S.mergeBy P.compare
541+ (sourceUnfoldrMN count n)
542+ (sourceUnfoldrMN count (n + 1))
539#ifdef INSPECTION
544#ifdef INSPECTION
540inspect $ hasNoTypeClasses 'mergeBy
545inspect $ hasNoTypeClasses 'mergeBy
541−-- inspect $ 'mergeBy `hasNoType` ''Step
546+inspect $ 'mergeBy `hasNoType` ''D.Step
549+{-# INLINE serial2 #-}
550+serial2 :: Int -> Int -> IO ()
553+ (sourceUnfoldrMN count n)
554+ (sourceUnfoldrMN count (n + 1))
556+{-# INLINE serial4 #-}
557+serial4 :: Int -> Int -> IO ()
560+ ((S.serial (sourceUnfoldrMN count n)
561+ (sourceUnfoldrMN count (n + 1))))
562+ ((S.serial (sourceUnfoldrMN count (n+2))
563+ (sourceUnfoldrMN count (n + 3))))
565+{-# INLINE append2 #-}
566+append2 :: Int -> Int -> IO ()
568+ S.drain $ Internal.append
569+ (sourceUnfoldrMN count n)
570+ (sourceUnfoldrMN count (n + 1))
572+{-# INLINE append4 #-}
573+append4 :: Int -> Int -> IO ()
575+ S.drain $ Internal.append
576+ ((Internal.append (sourceUnfoldrMN count n)
577+ (sourceUnfoldrMN count (n + 1))))
578+ ((Internal.append (sourceUnfoldrMN count (n+2))
579+ (sourceUnfoldrMN count (n + 3))))
582+inspect $ hasNoTypeClasses 'append2
583+inspect $ 'append2 `hasNoType` ''D.AppendState
586+{-# INLINE wSerial2 #-}
587+wSerial2 :: Int -> IO ()
588+wSerial2 n = S.drain $ S.wSerial
589+ (sourceUnfoldrMN (value `div` 2) n)
590+ (sourceUnfoldrMN (value `div` 2) (n + 1))
592+{-# INLINE interleave2 #-}
593+interleave2 :: Int -> IO ()
594+interleave2 n = S.drain $ Internal.interleave
595+ (sourceUnfoldrMN (value `div` 2) n)
596+ (sourceUnfoldrMN (value `div` 2) (n + 1))
599+inspect $ hasNoTypeClasses 'interleave2
600+inspect $ 'interleave2 `hasNoType` ''D.InterleaveState
603+{-# INLINE roundRobin2 #-}
604+roundRobin2 :: Int -> IO ()
605+roundRobin2 n = S.drain $ Internal.roundrobin
606+ (sourceUnfoldrMN (value `div` 2) n)
607+ (sourceUnfoldrMN (value `div` 2) (n + 1))
610+inspect $ hasNoTypeClasses 'roundRobin2
611+inspect $ 'roundRobin2 `hasNoType` ''D.InterleaveState
545{-# INLINE isPrefixOf #-}
614{-# INLINE isPrefixOf #-}
546{-# INLINE isSubsequenceOf #-}
615{-# INLINE isSubsequenceOf #-}
@@ -586,7 +655,7 @@ eqBy n = eqBy' (source n)
587#ifdef INSPECTION
656#ifdef INSPECTION
588inspect $ hasNoTypeClasses 'eqBy
657inspect $ hasNoTypeClasses 'eqBy
589−inspect $ 'eqBy `hasNoType` ''Step
658+inspect $ 'eqBy `hasNoType` ''D.Step
@@ -596,7 +665,7 @@ eqByPure n = eqBy' (sourceUnfoldr n)
597#ifdef INSPECTION
666#ifdef INSPECTION
598inspect $ hasNoTypeClasses 'eqByPure
667inspect $ hasNoTypeClasses 'eqByPure
599−inspect $ 'eqByPure `hasNoType` ''Step
668+inspect $ 'eqByPure `hasNoType` ''D.Step
602{-# INLINE cmpBy' #-}
671{-# INLINE cmpBy' #-}
@@ -609,7 +678,7 @@ cmpBy n = cmpBy' (source n)
610#ifdef INSPECTION
679#ifdef INSPECTION
611inspect $ hasNoTypeClasses 'cmpBy
680inspect $ hasNoTypeClasses 'cmpBy
612−inspect $ 'cmpBy `hasNoType` ''Step
681+inspect $ 'cmpBy `hasNoType` ''D.Step
615{-# INLINE cmpByPure #-}
684{-# INLINE cmpByPure #-}
@@ -618,38 +687,29 @@ cmpByPure n = cmpBy' (sourceUnfoldr n)
619#ifdef INSPECTION
688#ifdef INSPECTION
620inspect $ hasNoTypeClasses 'cmpByPure
689inspect $ hasNoTypeClasses 'cmpByPure
621−inspect $ 'cmpByPure `hasNoType` ''Step
690+inspect $ 'cmpByPure `hasNoType` ''D.Step
624−-- The worst case for concatMap, concat a 1 element stream n times.
625{-# INLINE concatMap #-}
693{-# INLINE concatMap #-}
626−concatMap :: Int -> IO ()
694+concatMap :: Int -> Int -> Int -> IO ()
695+concatMap outer inner n =
627−concatMap n = S.drain $ S.concatMap (\_ -> sourceUnfoldrMN 1 n)
696+ S.drain $ S.concatMap
697+ (\_ -> sourceUnfoldrMN inner n)
628− (sourceUnfoldrMN value n)
698+ (sourceUnfoldrMN outer n)
630#ifdef INSPECTION
700#ifdef INSPECTION
631inspect $ hasNoTypeClasses 'concatMap
701inspect $ hasNoTypeClasses 'concatMap
634−{-# INLINE concatMapPure1xN #-}
704+{-# INLINE concatMapPure #-}
635−concatMapPure1xN :: Int -> IO ()
705+concatMapPure :: Int -> Int -> Int -> IO ()
636−concatMapPure1xN n = S.drain $ S.concatMap (\_ -> sourceUnfoldrN 1 n)
706+concatMapPure outer inner n =
637− (sourceUnfoldrN value n)
640−inspect $ hasNoTypeClasses 'concatMapPure1xN
643−-- We use a (sqrt n) element stream as source and then generate and concat a
644−-- (sqrt n) element stream for each element of the source to produce an n
646−{-# INLINE concatMapNxN #-}
647−concatMapNxN :: Int -> IO ()
648−concatMapNxN n = S.drain $ S.concatMap (\_ -> sourceUnfoldrMN value2 n)
707+ S.drain $ S.concatMap
649− (sourceUnfoldrMN value2 n)
708+ (\_ -> sourceUnfoldrN inner n)
709+ (sourceUnfoldrN outer n)
651#ifdef INSPECTION
711#ifdef INSPECTION
652−inspect $ hasNoTypeClasses 'concatMapNxN
712+inspect $ hasNoTypeClasses 'concatMapPure
655{-# INLINE concatMapRepl4xN #-}
715{-# INLINE concatMapRepl4xN #-}
@@ -661,6 +721,75 @@ concatMapRepl4xN n = S.drain $ S.concatMap (S.replicate 4)
661inspect $ hasNoTypeClasses 'concatMapRepl4xN
721inspect $ hasNoTypeClasses 'concatMapRepl4xN
724+{-# INLINE concatUnfoldRepl4xN #-}
725+concatUnfoldRepl4xN :: Int -> IO ()
726+concatUnfoldRepl4xN n =
727+ S.drain $ Internal.concatMapU
729+ (sourceUnfoldrMN (value `div` 4) n)
732+inspect $ hasNoTypeClasses 'concatUnfoldRepl4xN
733+inspect $ 'concatUnfoldRepl4xN `hasNoType` ''D.ConcatMapUState
736+{-# INLINE concatMapWithSerial #-}
737+concatMapWithSerial :: Int -> Int -> Int -> IO ()
738+concatMapWithSerial outer inner n =
739+ S.drain $ S.concatMapWith S.serial
740+ (\_ -> sourceUnfoldrMN inner n)
741+ (sourceUnfoldrMN outer n)
744+inspect $ hasNoTypeClasses 'concatMapWithSerial
747+{-# INLINE concatMapWithAppend #-}
748+concatMapWithAppend :: Int -> Int -> Int -> IO ()
749+concatMapWithAppend outer inner n =
750+ S.drain $ S.concatMapWith Internal.append
751+ (\_ -> sourceUnfoldrMN inner n)
752+ (sourceUnfoldrMN outer n)
755+inspect $ hasNoTypeClasses 'concatMapWithAppend
758+{-# INLINE concatMapWithWSerial #-}
759+concatMapWithWSerial :: Int -> Int -> Int -> IO ()
760+concatMapWithWSerial outer inner n =
761+ S.drain $ S.concatMapWith S.wSerial
762+ (\_ -> sourceUnfoldrMN inner n)
763+ (sourceUnfoldrMN outer n)
766+inspect $ hasNoTypeClasses 'concatMapWithWSerial
769+{-# INLINE concatUnfoldInterleaveRepl4xN #-}
770+concatUnfoldInterleaveRepl4xN :: Int -> IO ()
771+concatUnfoldInterleaveRepl4xN n =
772+ S.drain $ Internal.concatUnfoldInterleave
774+ (sourceUnfoldrMN (value `div` 4) n)
777+inspect $ hasNoTypeClasses 'concatUnfoldInterleaveRepl4xN
778+-- inspect $ 'concatUnfoldInterleaveRepl4xN `hasNoType` ''D.ConcatUnfoldInterleaveState
781+{-# INLINE concatUnfoldRoundrobinRepl4xN #-}
782+concatUnfoldRoundrobinRepl4xN :: Int -> IO ()
783+concatUnfoldRoundrobinRepl4xN n =
784+ S.drain $ Internal.concatUnfoldRoundrobin
786+ (sourceUnfoldrMN (value `div` 4) n)
789+inspect $ hasNoTypeClasses 'concatUnfoldRoundrobinRepl4xN
790+-- inspect $ 'concatUnfoldRoundrobinRepl4xN `hasNoType` ''D.ConcatUnfoldInterleaveState
664-------------------------------------------------------------------------------
793-------------------------------------------------------------------------------
665-- Mixed Composition
794-- Mixed Composition
666-------------------------------------------------------------------------------
795-------------------------------------------------------------------------------