on master help sign in
Rename the CPS stream type to StreamK (#2269)
7252323Ranjeet Ranjan
benchmark/Streamly/Benchmark/Data/Stream/Common.hs+2−2
@@ -128,10 +128,10 @@ unCross = id
128type MonadAsync = Monad
128type MonadAsync = Monad
129
129
130#ifdef USE_STREAMK
130#ifdef USE_STREAMK
131−mkCross :: StreamK.Stream m a -> StreamK.CrossStreamK m a
131+mkCross :: StreamK m a -> StreamK.CrossStreamK m a
132mkCross = StreamK.mkCross
132mkCross = StreamK.mkCross
133
133
134−unCross :: StreamK.CrossStreamK m a -> StreamK.Stream m a
134+unCross :: StreamK.CrossStreamK m a -> StreamK m a
135unCross = StreamK.unCross
135unCross = StreamK.unCross
136#else
136#else
137mkCross :: Stream m a -> Stream.CrossStream m a
137mkCross :: Stream m a -> Stream.CrossStream m a
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+3−3
@@ -116,7 +116,7 @@ Benchmarks that need to be added
116-- Stream generation and elimination
116-- Stream generation and elimination
117-------------------------------------------------------------------------------
117-------------------------------------------------------------------------------
118
118
119−type Stream m a = S.Stream m a
119+type Stream m a = S.StreamK m a
120
120
121{-# INLINE unfoldr #-}
121{-# INLINE unfoldr #-}
122unfoldr :: Int -> Int -> Stream m Int
122unfoldr :: Int -> Int -> Stream m Int
@@ -501,7 +501,7 @@ concatMapBySerial outer inner n =
501-- Nested Composition
501-- Nested Composition
502-------------------------------------------------------------------------------
502-------------------------------------------------------------------------------
503
503
504−instance Monad m => Applicative (S.Stream m) where
504+instance Monad m => Applicative (S.StreamK m) where
505 {-# INLINE pure #-}
505 {-# INLINE pure #-}
506 pure = S.fromPure
506 pure = S.fromPure
507
507
@@ -520,7 +520,7 @@ instance Monad m => Applicative (S.Stream m) where
520-- NOTE: even though concatMap for StreamD is 3x faster compared to StreamK,
520-- NOTE: even though concatMap for StreamD is 3x faster compared to StreamK,
521-- the monad instance of StreamD is slower than StreamK after foldr/build
521-- the monad instance of StreamD is slower than StreamK after foldr/build
522-- fusion.
522-- fusion.
523−instance Monad m => Monad (S.Stream m) where
523+instance Monad m => Monad (S.StreamK m) where
524 {-# INLINE return #-}
524 {-# INLINE return #-}
525 return = pure
525 return = pure
526
526
core/src/Streamly/Internal/Data/Array/Generic/Mut/Type.hs+1−1
@@ -498,7 +498,7 @@ toStreamD arr@Array{..} =
498 D.mapM (`getIndexUnsafe` arr) $ D.enumerateFromToIntegral 0 (arrLen - 1)
498 D.mapM (`getIndexUnsafe` arr) $ D.enumerateFromToIntegral 0 (arrLen - 1)
499
499
500{-# INLINE toStreamK #-}
500{-# INLINE toStreamK #-}
501−toStreamK :: MonadIO m => Array a -> K.Stream m a
501+toStreamK :: MonadIO m => Array a -> K.StreamK m a
502toStreamK arr@Array{..} = K.unfoldrM step 0
502toStreamK arr@Array{..} = K.unfoldrM step 0
503
503
504 where
504 where
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+9−8
@@ -244,6 +244,7 @@ import GHC.Ptr (Ptr(..))
244import Streamly.Internal.Data.Fold.Type (Fold(..))
244import Streamly.Internal.Data.Fold.Type (Fold(..))
245import Streamly.Internal.Data.Producer.Type (Producer (..))
245import Streamly.Internal.Data.Producer.Type (Producer (..))
246import Streamly.Internal.Data.Stream.StreamD.Type (Stream)
246import Streamly.Internal.Data.Stream.StreamD.Type (Stream)
247+import Streamly.Internal.Data.Stream.StreamK.Type (StreamK)
247import Streamly.Internal.Data.SVar.Type (adaptState, defState)
248import Streamly.Internal.Data.SVar.Type (adaptState, defState)
248import Streamly.Internal.Data.Unfold.Type (Unfold(..))
249import Streamly.Internal.Data.Unfold.Type (Unfold(..))
249import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
250import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
@@ -1339,7 +1340,7 @@ arraysOf n (D.Stream step state) =
1339-- | Buffer the stream into arrays in memory.
1340-- | Buffer the stream into arrays in memory.
1340{-# INLINE arrayStreamKFromStreamD #-}
1341{-# INLINE arrayStreamKFromStreamD #-}
1341arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unbox a) =>
1342arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unbox a) =>
1342− D.Stream m a -> m (K.Stream m (MutArray a))
1343+ D.Stream m a -> m (StreamK m (MutArray a))
1343arrayStreamKFromStreamD =
1344arrayStreamKFromStreamD =
1344 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
1345 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
1345 in D.foldr K.cons K.nil . arraysOf n
1346 in D.foldr K.cons K.nil . arraysOf n
@@ -1554,7 +1555,7 @@ toStreamD = toStreamDWith liftIO
1554{-# INLINE toStreamKWith #-}
1555{-# INLINE toStreamKWith #-}
1555toStreamKWith ::
1556toStreamKWith ::
1556 forall m a. (Monad m, Unbox a)
1557 forall m a. (Monad m, Unbox a)
1557− => (forall b. IO b -> m b) -> MutArray a -> K.Stream m a
1558+ => (forall b. IO b -> m b) -> MutArray a -> StreamK m a
1558toStreamKWith liftio MutArray{..} = go arrStart
1559toStreamKWith liftio MutArray{..} = go arrStart
1559
1560
1560 where
1561 where
@@ -1565,7 +1566,7 @@ toStreamKWith liftio MutArray{..} = go arrStart
1565 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1566 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1566
1567
1567{-# INLINE toStreamK #-}
1568{-# INLINE toStreamK #-}
1568−toStreamK :: forall m a. (MonadIO m, Unbox a) => MutArray a -> K.Stream m a
1569+toStreamK :: forall m a. (MonadIO m, Unbox a) => MutArray a -> StreamK m a
1569toStreamK = toStreamKWith liftIO
1570toStreamK = toStreamKWith liftIO
1570
1571
1571{-# INLINE_NORMAL toStreamDRevWith #-}
1572{-# INLINE_NORMAL toStreamDRevWith #-}
@@ -1596,7 +1597,7 @@ toStreamDRev = toStreamDRevWith liftIO
1596{-# INLINE toStreamKRevWith #-}
1597{-# INLINE toStreamKRevWith #-}
1597toStreamKRevWith ::
1598toStreamKRevWith ::
1598 forall m a. (Monad m, Unbox a)
1599 forall m a. (Monad m, Unbox a)
1599− => (forall b. IO b -> m b) -> MutArray a -> K.Stream m a
1600+ => (forall b. IO b -> m b) -> MutArray a -> StreamK m a
1600toStreamKRevWith liftio MutArray {..} =
1601toStreamKRevWith liftio MutArray {..} =
1601 let p = INDEX_PREV(arrEnd,a)
1602 let p = INDEX_PREV(arrEnd,a)
1602 in go p
1603 in go p
@@ -1609,7 +1610,7 @@ toStreamKRevWith liftio MutArray {..} =
1609 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1610 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1610
1611
1611{-# INLINE toStreamKRev #-}
1612{-# INLINE toStreamKRev #-}
1612−toStreamKRev :: forall m a. (MonadIO m, Unbox a) => MutArray a -> K.Stream m a
1613+toStreamKRev :: forall m a. (MonadIO m, Unbox a) => MutArray a -> StreamK m a
1613toStreamKRev = toStreamKRevWith liftIO
1614toStreamKRev = toStreamKRevWith liftIO
1614
1615
1615-------------------------------------------------------------------------------
1616-------------------------------------------------------------------------------
@@ -1836,7 +1837,7 @@ writeNAligned align = writeNWith (newAlignedPinned align)
1836--
1837--
1837{-# INLINE_NORMAL writeChunks #-}
1838{-# INLINE_NORMAL writeChunks #-}
1838writeChunks :: (MonadIO m, Unbox a) =>
1839writeChunks :: (MonadIO m, Unbox a) =>
1839− Int -> Fold m a (K.Stream n (MutArray a))
1840+ Int -> Fold m a (StreamK n (MutArray a))
1840writeChunks n = FL.many (writeN n) FL.toStreamK
1841writeChunks n = FL.many (writeN n) FL.toStreamK
1841
1842
1842-- XXX Compare writeWith with fromStreamD which uses an array of streams
1843-- XXX Compare writeWith with fromStreamD which uses an array of streams
@@ -1946,7 +1947,7 @@ fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1946-------------------------------------------------------------------------------
1947-------------------------------------------------------------------------------
1947
1948
1948{-# INLINE arrayStreamKLength #-}
1949{-# INLINE arrayStreamKLength #-}
1949−arrayStreamKLength :: (Monad m, Unbox a) => K.Stream m (MutArray a) -> m Int
1950+arrayStreamKLength :: (Monad m, Unbox a) => StreamK m (MutArray a) -> m Int
1950arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1951arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1951
1952
1952-- | Convert an array stream to an array. Note that this requires peak memory
1953-- | Convert an array stream to an array. Note that this requires peak memory
@@ -1954,7 +1955,7 @@ arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1954--
1955--
1955{-# INLINE fromArrayStreamK #-}
1956{-# INLINE fromArrayStreamK #-}
1956fromArrayStreamK :: (Unbox a, MonadIO m) =>
1957fromArrayStreamK :: (Unbox a, MonadIO m) =>
1957− K.Stream m (MutArray a) -> m (MutArray a)
1958+ StreamK m (MutArray a) -> m (MutArray a)
1958fromArrayStreamK as = do
1959fromArrayStreamK as = do
1959 len <- arrayStreamKLength as
1960 len <- arrayStreamKLength as
1960 fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
1961 fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
core/src/Streamly/Internal/Data/Array/Type.hs+3−3
@@ -262,7 +262,7 @@ fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
262
262
263{-# INLINE bufferChunks #-}
263{-# INLINE bufferChunks #-}
264bufferChunks :: (MonadIO m, Unbox a) =>
264bufferChunks :: (MonadIO m, Unbox a) =>
265− D.Stream m a -> m (K.Stream m (Array a))
265+ D.Stream m a -> m (K.StreamK m (Array a))
266bufferChunks m = D.foldr K.cons K.nil $ arraysOf defaultChunkSize m
266bufferChunks m = D.foldr K.cons K.nil $ arraysOf defaultChunkSize m
267
267
268-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
268-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
@@ -348,7 +348,7 @@ toStreamD :: forall m a. (Monad m, Unbox a) => Array a -> D.Stream m a
348toStreamD arr = MA.toStreamDWith (return . unsafeInlineIO) (unsafeThaw arr)
348toStreamD arr = MA.toStreamDWith (return . unsafeInlineIO) (unsafeThaw arr)
349
349
350{-# INLINE toStreamK #-}
350{-# INLINE toStreamK #-}
351−toStreamK :: forall m a. (Monad m, Unbox a) => Array a -> K.Stream m a
351+toStreamK :: forall m a. (Monad m, Unbox a) => Array a -> K.StreamK m a
352toStreamK arr = MA.toStreamKWith (return . unsafeInlineIO) (unsafeThaw arr)
352toStreamK arr = MA.toStreamKWith (return . unsafeInlineIO) (unsafeThaw arr)
353
353
354{-# INLINE_NORMAL toStreamDRev #-}
354{-# INLINE_NORMAL toStreamDRev #-}
@@ -357,7 +357,7 @@ toStreamDRev arr =
357 MA.toStreamDRevWith (return . unsafeInlineIO) (unsafeThaw arr)
357 MA.toStreamDRevWith (return . unsafeInlineIO) (unsafeThaw arr)
358
358
359{-# INLINE toStreamKRev #-}
359{-# INLINE toStreamKRev #-}
360−toStreamKRev :: forall m a. (Monad m, Unbox a) => Array a -> K.Stream m a
360+toStreamKRev :: forall m a. (Monad m, Unbox a) => Array a -> K.StreamK m a
361toStreamKRev arr =
361toStreamKRev arr =
362 MA.toStreamKRevWith (return . unsafeInlineIO) (unsafeThaw arr)
362 MA.toStreamKRevWith (return . unsafeInlineIO) (unsafeThaw arr)
363
363
core/src/Streamly/Internal/Data/Fold/Type.hs+2−2
@@ -688,7 +688,7 @@ toList = foldr' (:) []
688
688
689-- xn : ... : x2 : x1 : []
689-- xn : ... : x2 : x1 : []
690{-# INLINE toStreamKRev #-}
690{-# INLINE toStreamKRev #-}
691−toStreamKRev :: Monad m => Fold m a (K.Stream n a)
691+toStreamKRev :: Monad m => Fold m a (K.StreamK n a)
692toStreamKRev = foldl' (flip K.cons) K.nil
692toStreamKRev = foldl' (flip K.cons) K.nil
693
693
694-- | A fold that buffers its input to a pure stream.
694-- | A fold that buffers its input to a pure stream.
@@ -698,7 +698,7 @@ toStreamKRev = foldl' (flip K.cons) K.nil
698--
698--
699-- /Internal/
699-- /Internal/
700{-# INLINE toStreamK #-}
700{-# INLINE toStreamK #-}
701−toStreamK :: Monad m => Fold m a (K.Stream n a)
701+toStreamK :: Monad m => Fold m a (K.StreamK n a)
702toStreamK = foldr K.cons K.nil
702toStreamK = foldr K.cons K.nil
703
703
704------------------------------------------------------------------------------
704------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Stream/Chunked.hs+3−3
@@ -367,7 +367,7 @@ foldBreakD (FL.Fold fstep initial extract) stream@(D.Stream step state) = do
367
367
368{-# INLINE_NORMAL foldBreakK #-}
368{-# INLINE_NORMAL foldBreakK #-}
369foldBreakK :: forall m a b. (MonadIO m, Unbox a) =>
369foldBreakK :: forall m a b. (MonadIO m, Unbox a) =>
370− Fold m a b -> K.Stream m (Array a) -> m (b, K.Stream m (Array a))
370+ Fold m a b -> K.StreamK m (Array a) -> m (b, K.StreamK m (Array a))
371foldBreakK (FL.Fold fstep initial extract) stream = do
371foldBreakK (FL.Fold fstep initial extract) stream = do
372 res <- initial
372 res <- initial
373 case res of
373 case res of
@@ -644,8 +644,8 @@ parseBreakD
644parseBreakK ::
644parseBreakK ::
645 forall m a b. (MonadIO m, Unbox a)
645 forall m a b. (MonadIO m, Unbox a)
646 => PRD.Parser a m b
646 => PRD.Parser a m b
647− -> K.Stream m (Array.Array a)
647+ -> K.StreamK m (Array.Array a)
648− -> m (Either ParseError b, K.Stream m (Array.Array a))
648+ -> m (Either ParseError b, K.StreamK m (Array.Array a))
649parseBreakK (PRD.Parser pstep initial extract) stream = do
649parseBreakK (PRD.Parser pstep initial extract) stream = do
650 res <- initial
650 res <- initial
651 case res of
651 case res of
core/src/Streamly/Internal/Data/Stream/Common.hs+8−8
@@ -50,7 +50,7 @@ import Prelude hiding (foldr, repeat)
50-- 'K.fromFoldable' for serial streams.
50-- 'K.fromFoldable' for serial streams.
51--
51--
52{-# INLINE_EARLY fromList #-}
52{-# INLINE_EARLY fromList #-}
53−fromList :: Monad m => [a] -> K.Stream m a
53+fromList :: Monad m => [a] -> K.StreamK m a
54fromList = D.toStreamK . D.fromList
54fromList = D.toStreamK . D.fromList
55{-# RULES "fromList fallback to StreamK" [1]
55{-# RULES "fromList fallback to StreamK" [1]
56 forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
56 forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
@@ -58,7 +58,7 @@ fromList = D.toStreamK . D.fromList
58-- | Convert a stream into a list in the underlying monad.
58-- | Convert a stream into a list in the underlying monad.
59--
59--
60{-# INLINE toList #-}
60{-# INLINE toList #-}
61−toList :: Monad m => K.Stream m a -> m [a]
61+toList :: Monad m => K.StreamK m a -> m [a]
62toList m = D.toList $ D.fromStreamK m
62toList m = D.toList $ D.fromStreamK m
63
63
64------------------------------------------------------------------------------
64------------------------------------------------------------------------------
@@ -66,23 +66,23 @@ toList m = D.toList $ D.fromStreamK m
66------------------------------------------------------------------------------
66------------------------------------------------------------------------------
67
67
68{-# INLINE foldrM #-}
68{-# INLINE foldrM #-}
69−foldrM :: Monad m => (a -> m b -> m b) -> m b -> K.Stream m a -> m b
69+foldrM :: Monad m => (a -> m b -> m b) -> m b -> K.StreamK m a -> m b
70foldrM step acc m = D.foldrM step acc $ D.fromStreamK m
70foldrM step acc m = D.foldrM step acc $ D.fromStreamK m
71
71
72{-# INLINE foldr #-}
72{-# INLINE foldr #-}
73−foldr :: Monad m => (a -> b -> b) -> b -> K.Stream m a -> m b
73+foldr :: Monad m => (a -> b -> b) -> b -> K.StreamK m a -> m b
74foldr f z = foldrM (\a b -> f a <$> b) (return z)
74foldr f z = foldrM (\a b -> f a <$> b) (return z)
75
75
76-- | Strict left associative fold.
76-- | Strict left associative fold.
77--
77--
78{-# INLINE foldl' #-}
78{-# INLINE foldl' #-}
79foldl' ::
79foldl' ::
80− Monad m => (b -> a -> b) -> b -> K.Stream m a -> m b
80+ Monad m => (b -> a -> b) -> b -> K.StreamK m a -> m b
81foldl' step begin m = D.foldl' step begin $ D.fromStreamK m
81foldl' step begin m = D.foldl' step begin $ D.fromStreamK m
82
82
83
83
84{-# INLINE fold #-}
84{-# INLINE fold #-}
85−fold :: Monad m => Fold m a b -> K.Stream m a -> m b
85+fold :: Monad m => Fold m a b -> K.StreamK m a -> m b
86fold fld m = D.fold fld $ D.fromStreamK m
86fold fld m = D.fold fld $ D.fromStreamK m
87
87
88------------------------------------------------------------------------------
88------------------------------------------------------------------------------
@@ -93,7 +93,7 @@ fold fld m = D.fold fld $ D.fromStreamK m
93--
93--
94{-# INLINE eqBy #-}
94{-# INLINE eqBy #-}
95eqBy :: Monad m =>
95eqBy :: Monad m =>
96− (a -> b -> Bool) -> K.Stream m a -> K.Stream m b -> m Bool
96+ (a -> b -> Bool) -> K.StreamK m a -> K.StreamK m b -> m Bool
97eqBy f m1 m2 = D.eqBy f (D.fromStreamK m1) (D.fromStreamK m2)
97eqBy f m1 m2 = D.eqBy f (D.fromStreamK m1) (D.fromStreamK m2)
98
98
99-- | Compare two streams
99-- | Compare two streams
@@ -101,5 +101,5 @@ eqBy f m1 m2 = D.eqBy f (D.fromStreamK m1) (D.fromStreamK m2)
101{-# INLINE cmpBy #-}
101{-# INLINE cmpBy #-}
102cmpBy
102cmpBy
103 :: Monad m
103 :: Monad m
104− => (a -> b -> Ordering) -> K.Stream m a -> K.Stream m b -> m Ordering
104+ => (a -> b -> Ordering) -> K.StreamK m a -> K.StreamK m b -> m Ordering
105cmpBy f m1 m2 = D.cmpBy f (D.fromStreamK m1) (D.fromStreamK m2)
105cmpBy f m1 m2 = D.cmpBy f (D.fromStreamK m1) (D.fromStreamK m2)
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+4−4
@@ -186,7 +186,7 @@ import qualified Streamly.Internal.Data.Unfold.Type as Unfold
186-- | A stream consists of a step function that generates the next step given a
186-- | A stream consists of a step function that generates the next step given a
187-- current state, and the current state.
187-- current state, and the current state.
188data Stream m a =
188data Stream m a =
189− forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
189+ forall s. UnStream (State K.StreamK m a -> s -> m (Step s a)) s
190
190
191-- XXX This causes perf trouble when pattern matching with "Stream" in a
191-- XXX This causes perf trouble when pattern matching with "Stream" in a
192-- recursive way, e.g. in uncons, foldBreak, concatMap. We need to get rid of
192-- recursive way, e.g. in uncons, foldBreak, concatMap. We need to get rid of
@@ -195,7 +195,7 @@ unShare :: Stream m a -> Stream m a
195unShare (UnStream step state) = UnStream step' state
195unShare (UnStream step state) = UnStream step' state
196 where step' gst = step (adaptState gst)
196 where step' gst = step (adaptState gst)
197
197
198−pattern Stream :: (State K.Stream m a -> s -> m (Step s a)) -> s -> Stream m a
198+pattern Stream :: (State K.StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
199pattern Stream step state <- (unShare -> UnStream step state)
199pattern Stream step state <- (unShare -> UnStream step state)
200 where Stream = UnStream
200 where Stream = UnStream
201
201
@@ -361,7 +361,7 @@ fromList = Stream step
361
361
362-- | Convert a CPS encoded StreamK to direct style step encoded StreamD
362-- | Convert a CPS encoded StreamK to direct style step encoded StreamD
363{-# INLINE_LATE fromStreamK #-}
363{-# INLINE_LATE fromStreamK #-}
364−fromStreamK :: Applicative m => K.Stream m a -> Stream m a
364+fromStreamK :: Applicative m => K.StreamK m a -> Stream m a
365fromStreamK = Stream step
365fromStreamK = Stream step
366 where
366 where
367 step gst m1 =
367 step gst m1 =
@@ -372,7 +372,7 @@ fromStreamK = Stream step
372
372
373-- | Convert a direct style step encoded StreamD to a CPS encoded StreamK
373-- | Convert a direct style step encoded StreamD to a CPS encoded StreamK
374{-# INLINE_LATE toStreamK #-}
374{-# INLINE_LATE toStreamK #-}
375−toStreamK :: Monad m => Stream m a -> K.Stream m a
375+toStreamK :: Monad m => Stream m a -> K.StreamK m a
376toStreamK (Stream step state) = go state
376toStreamK (Stream step state) = go state
377 where
377 where
378 go st = K.MkStream $ \gst yld _ stp ->
378 go st = K.MkStream $ \gst yld _ stp ->
core/src/Streamly/Internal/Data/Stream/StreamK.hs+61−61
@@ -49,8 +49,8 @@
49module Streamly.Internal.Data.Stream.StreamK
49module Streamly.Internal.Data.Stream.StreamK
50 (
50 (
51 -- * The stream type
51 -- * The stream type
52− Stream(..) -- XXX stop exporting this
52+ Stream
53− , StreamK
53+ , StreamK(..)
54 , fromStream
54 , fromStream
55 , toStream
55 , toStream
56
56
@@ -285,7 +285,7 @@ toStream = Stream.fromStreamK
285-- concurrent version could be async or ahead etc. Depending on how we queue
285-- concurrent version could be async or ahead etc. Depending on how we queue
286-- back the feedback portion b, it could be DFS or BFS style.
286-- back the feedback portion b, it could be DFS or BFS style.
287--
287--
288−unfoldrA :: (b -> Maybe (m a, b)) -> b -> Stream m a
288+unfoldrA :: (b -> Maybe (m a, b)) -> b -> StreamK m a
289unfoldrA = undefined
289unfoldrA = undefined
290-}
290-}
291
291
@@ -293,35 +293,35 @@ unfoldrA = undefined
293-- Special generation
293-- Special generation
294-------------------------------------------------------------------------------
294-------------------------------------------------------------------------------
295
295
296−repeatM :: Monad m => m a -> Stream m a
296+repeatM :: Monad m => m a -> StreamK m a
297repeatM = repeatMWith consM
297repeatM = repeatMWith consM
298
298
299{-# INLINE replicateM #-}
299{-# INLINE replicateM #-}
300−replicateM :: Monad m => Int -> m a -> Stream m a
300+replicateM :: Monad m => Int -> m a -> StreamK m a
301replicateM = replicateMWith consM
301replicateM = replicateMWith consM
302{-# INLINE replicate #-}
302{-# INLINE replicate #-}
303−replicate :: Int -> a -> Stream m a
303+replicate :: Int -> a -> StreamK m a
304replicate n a = go n
304replicate n a = go n
305 where
305 where
306 go cnt = if cnt <= 0 then nil else a `cons` go (cnt - 1)
306 go cnt = if cnt <= 0 then nil else a `cons` go (cnt - 1)
307
307
308{-# INLINE fromIndicesM #-}
308{-# INLINE fromIndicesM #-}
309−fromIndicesM :: Monad m => (Int -> m a) -> Stream m a
309+fromIndicesM :: Monad m => (Int -> m a) -> StreamK m a
310fromIndicesM = fromIndicesMWith consM
310fromIndicesM = fromIndicesMWith consM
311{-# INLINE fromIndices #-}
311{-# INLINE fromIndices #-}
312−fromIndices :: (Int -> a) -> Stream m a
312+fromIndices :: (Int -> a) -> StreamK m a
313fromIndices gen = go 0
313fromIndices gen = go 0
314 where
314 where
315 go n = gen n `cons` go (n + 1)
315 go n = gen n `cons` go (n + 1)
316
316
317{-# INLINE iterate #-}
317{-# INLINE iterate #-}
318−iterate :: (a -> a) -> a -> Stream m a
318+iterate :: (a -> a) -> a -> StreamK m a
319iterate step = go
319iterate step = go
320 where
320 where
321 go !s = cons s (go (step s))
321 go !s = cons s (go (step s))
322
322
323{-# INLINE iterateM #-}
323{-# INLINE iterateM #-}
324−iterateM :: Monad m => (a -> m a) -> m a -> Stream m a
324+iterateM :: Monad m => (a -> m a) -> m a -> StreamK m a
325iterateM = iterateMWith consM
325iterateM = iterateMWith consM
326
326
327-------------------------------------------------------------------------------
327-------------------------------------------------------------------------------
@@ -329,7 +329,7 @@ iterateM = iterateMWith consM
329-------------------------------------------------------------------------------
329-------------------------------------------------------------------------------
330
330
331{-# INLINE fromList #-}
331{-# INLINE fromList #-}
332−fromList :: [a] -> Stream m a
332+fromList :: [a] -> StreamK m a
333fromList = fromFoldable
333fromList = fromFoldable
334
334
335-------------------------------------------------------------------------------
335-------------------------------------------------------------------------------
@@ -337,7 +337,7 @@ fromList = fromFoldable
337-------------------------------------------------------------------------------
337-------------------------------------------------------------------------------
338
338
339{-# INLINE foldr1 #-}
339{-# INLINE foldr1 #-}
340−foldr1 :: Monad m => (a -> a -> a) -> Stream m a -> m (Maybe a)
340+foldr1 :: Monad m => (a -> a -> a) -> StreamK m a -> m (Maybe a)
341foldr1 step m = do
341foldr1 step m = do
342 r <- uncons m
342 r <- uncons m
343 case r of
343 case r of
@@ -354,7 +354,7 @@ foldr1 step m = do
354-- | Like 'foldx', but with a monadic step function.
354-- | Like 'foldx', but with a monadic step function.
355{-# INLINABLE foldlMx' #-}
355{-# INLINABLE foldlMx' #-}
356foldlMx' :: Monad m
356foldlMx' :: Monad m
357− => (x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> m b
357+ => (x -> a -> m x) -> m x -> (x -> m b) -> StreamK m a -> m b
358foldlMx' step begin done = go begin
358foldlMx' step begin done = go begin
359 where
359 where
360 go !acc m1 =
360 go !acc m1 =
@@ -379,7 +379,7 @@ foldlMx' step begin done = go begin
379-- 5050
379-- 5050
380--
380--
381{-# INLINABLE fold #-}
381{-# INLINABLE fold #-}
382−fold :: Monad m => FL.Fold m a b -> Stream m a -> m b
382+fold :: Monad m => FL.Fold m a b -> StreamK m a -> m b
383fold (FL.Fold step begin done) m = do
383fold (FL.Fold step begin done) m = do
384 res <- begin
384 res <- begin
385 case res of
385 case res of
@@ -408,7 +408,7 @@ fold (FL.Fold step begin done) m = do
408-- /Internal/
408-- /Internal/
409{-# INLINE foldEither #-}
409{-# INLINE foldEither #-}
410foldEither :: Monad m =>
410foldEither :: Monad m =>
411− Fold m a b -> Stream m a -> m (Either (Fold m a b) (b, Stream m a))
411+ Fold m a b -> StreamK m a -> m (Either (Fold m a b) (b, StreamK m a))
412foldEither (FL.Fold step begin done) m = do
412foldEither (FL.Fold step begin done) m = do
413 res <- begin
413 res <- begin
414 case res of
414 case res of
@@ -436,7 +436,7 @@ foldEither (FL.Fold step begin done) m = do
436-- would be 'StreamK.nil' if the stream finished before the fold.
436-- would be 'StreamK.nil' if the stream finished before the fold.
437--
437--
438{-# INLINE foldBreak #-}
438{-# INLINE foldBreak #-}
439−foldBreak :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
439+foldBreak :: Monad m => Fold m a b -> StreamK m a -> m (b, StreamK m a)
440foldBreak fld strm = do
440foldBreak fld strm = do
441 r <- foldEither fld strm
441 r <- foldEither fld strm
442 case r of
442 case r of
@@ -513,7 +513,7 @@ foldConcat
513
513
514-- | Like 'foldl'' but with a monadic step function.
514-- | Like 'foldl'' but with a monadic step function.
515{-# INLINE foldlM' #-}
515{-# INLINE foldlM' #-}
516−foldlM' :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> m b
516+foldlM' :: Monad m => (b -> a -> m b) -> m b -> StreamK m a -> m b
517foldlM' step begin = foldlMx' step begin return
517foldlM' step begin = foldlMx' step begin return
518
518
519------------------------------------------------------------------------------
519------------------------------------------------------------------------------
@@ -521,7 +521,7 @@ foldlM' step begin = foldlMx' step begin return
521------------------------------------------------------------------------------
521------------------------------------------------------------------------------
522
522
523{-# INLINE head #-}
523{-# INLINE head #-}
524−head :: Monad m => Stream m a -> m (Maybe a)
524+head :: Monad m => StreamK m a -> m (Maybe a)
525-- head = foldrM (\x _ -> return $ Just x) (return Nothing)
525-- head = foldrM (\x _ -> return $ Just x) (return Nothing)
526head m =
526head m =
527 let stop = return Nothing
527 let stop = return Nothing
@@ -530,7 +530,7 @@ head m =
530 in foldStream defState yieldk single stop m
530 in foldStream defState yieldk single stop m
531
531
532{-# INLINE elem #-}
532{-# INLINE elem #-}
533−elem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
533+elem :: (Monad m, Eq a) => a -> StreamK m a -> m Bool
534elem e = go
534elem e = go
535 where
535 where
536 go m1 =
536 go m1 =
@@ -540,7 +540,7 @@ elem e = go
540 in foldStream defState yieldk single stop m1
540 in foldStream defState yieldk single stop m1
541
541
542{-# INLINE notElem #-}
542{-# INLINE notElem #-}
543−notElem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
543+notElem :: (Monad m, Eq a) => a -> StreamK m a -> m Bool
544notElem e = go
544notElem e = go
545 where
545 where
546 go m1 =
546 go m1 =
@@ -550,7 +550,7 @@ notElem e = go
550 in foldStream defState yieldk single stop m1
550 in foldStream defState yieldk single stop m1
551
551
552{-# INLINABLE all #-}
552{-# INLINABLE all #-}
553−all :: Monad m => (a -> Bool) -> Stream m a -> m Bool
553+all :: Monad m => (a -> Bool) -> StreamK m a -> m Bool
554all p = go
554all p = go
555 where
555 where
556 go m1 =
556 go m1 =
@@ -561,7 +561,7 @@ all p = go
561 in foldStream defState yieldk single (return True) m1
561 in foldStream defState yieldk single (return True) m1
562
562
563{-# INLINABLE any #-}
563{-# INLINABLE any #-}
564−any :: Monad m => (a -> Bool) -> Stream m a -> m Bool
564+any :: Monad m => (a -> Bool) -> StreamK m a -> m Bool
565any p = go
565any p = go
566 where
566 where
567 go m1 =
567 go m1 =
@@ -573,11 +573,11 @@ any p = go
573
573
574-- | Extract the last element of the stream, if any.
574-- | Extract the last element of the stream, if any.
575{-# INLINE last #-}
575{-# INLINE last #-}
576−last :: Monad m => Stream m a -> m (Maybe a)
576+last :: Monad m => StreamK m a -> m (Maybe a)
577last = foldlx' (\_ y -> Just y) Nothing id
577last = foldlx' (\_ y -> Just y) Nothing id
578
578
579{-# INLINE minimum #-}
579{-# INLINE minimum #-}
580−minimum :: (Monad m, Ord a) => Stream m a -> m (Maybe a)
580+minimum :: (Monad m, Ord a) => StreamK m a -> m (Maybe a)
581minimum = go Nothing
581minimum = go Nothing
582 where
582 where
583 go Nothing m1 =
583 go Nothing m1 =
@@ -601,7 +601,7 @@ minimum = go Nothing
601{-# INLINE minimumBy #-}
601{-# INLINE minimumBy #-}
602minimumBy
602minimumBy
603 :: (Monad m)
603 :: (Monad m)
604− => (a -> a -> Ordering) -> Stream m a -> m (Maybe a)
604+ => (a -> a -> Ordering) -> StreamK m a -> m (Maybe a)
605minimumBy cmp = go Nothing
605minimumBy cmp = go Nothing
606 where
606 where
607 go Nothing m1 =
607 go Nothing m1 =
@@ -621,7 +621,7 @@ minimumBy cmp = go Nothing
621 in foldStream defState yieldk single stop m1
621 in foldStream defState yieldk single stop m1
622
622
623{-# INLINE maximum #-}
623{-# INLINE maximum #-}
624−maximum :: (Monad m, Ord a) => Stream m a -> m (Maybe a)
624+maximum :: (Monad m, Ord a) => StreamK m a -> m (Maybe a)
625maximum = go Nothing
625maximum = go Nothing
626 where
626 where
627 go Nothing m1 =
627 go Nothing m1 =
@@ -643,7 +643,7 @@ maximum = go Nothing
643 in foldStream defState yieldk single stop m1
643 in foldStream defState yieldk single stop m1
644
644
645{-# INLINE maximumBy #-}
645{-# INLINE maximumBy #-}
646−maximumBy :: Monad m => (a -> a -> Ordering) -> Stream m a -> m (Maybe a)
646+maximumBy :: Monad m => (a -> a -> Ordering) -> StreamK m a -> m (Maybe a)
647maximumBy cmp = go Nothing
647maximumBy cmp = go Nothing
648 where
648 where
649 go Nothing m1 =
649 go Nothing m1 =
@@ -663,7 +663,7 @@ maximumBy cmp = go Nothing
663 in foldStream defState yieldk single stop m1
663 in foldStream defState yieldk single stop m1
664
664
665{-# INLINE (!!) #-}
665{-# INLINE (!!) #-}
666−(!!) :: Monad m => Stream m a -> Int -> m (Maybe a)
666+(!!) :: Monad m => StreamK m a -> Int -> m (Maybe a)
667m !! i = go i m
667m !! i = go i m
668 where
668 where
669 go n m1 =
669 go n m1 =
@@ -675,7 +675,7 @@ m !! i = go i m
675 in foldStream defState yieldk single (return Nothing) m1
675 in foldStream defState yieldk single (return Nothing) m1
676
676
677{-# INLINE lookup #-}
677{-# INLINE lookup #-}
678−lookup :: (Monad m, Eq a) => a -> Stream m (a, b) -> m (Maybe b)
678+lookup :: (Monad m, Eq a) => a -> StreamK m (a, b) -> m (Maybe b)
679lookup e = go
679lookup e = go
680 where
680 where
681 go m1 =
681 go m1 =
@@ -686,7 +686,7 @@ lookup e = go
686 in foldStream defState yieldk single (return Nothing) m1
686 in foldStream defState yieldk single (return Nothing) m1
687
687
688{-# INLINE findM #-}
688{-# INLINE findM #-}
689−findM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe a)
689+findM :: Monad m => (a -> m Bool) -> StreamK m a -> m (Maybe a)
690findM p = go
690findM p = go
691 where
691 where
692 go m1 =
692 go m1 =
@@ -699,11 +699,11 @@ findM p = go
699 in foldStream defState yieldk single (return Nothing) m1
699 in foldStream defState yieldk single (return Nothing) m1
700
700
701{-# INLINE find #-}
701{-# INLINE find #-}
702−find :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe a)
702+find :: Monad m => (a -> Bool) -> StreamK m a -> m (Maybe a)
703find p = findM (return . p)
703find p = findM (return . p)
704
704
705{-# INLINE findIndices #-}
705{-# INLINE findIndices #-}
706−findIndices :: (a -> Bool) -> Stream m a -> Stream m Int
706+findIndices :: (a -> Bool) -> StreamK m a -> StreamK m Int
707findIndices p = go 0
707findIndices p = go 0
708 where
708 where
709 go offset m1 = mkStream $ \st yld sng stp ->
709 go offset m1 = mkStream $ \st yld sng stp ->
@@ -721,7 +721,7 @@ findIndices p = go 0
721-- | Apply a monadic action to each element of the stream and discard the
721-- | Apply a monadic action to each element of the stream and discard the
722-- output of the action.
722-- output of the action.
723{-# INLINE mapM_ #-}
723{-# INLINE mapM_ #-}
724−mapM_ :: Monad m => (a -> m b) -> Stream m a -> m ()
724+mapM_ :: Monad m => (a -> m b) -> StreamK m a -> m ()
725mapM_ f = go
725mapM_ f = go
726 where
726 where
727 go m1 =
727 go m1 =
@@ -731,7 +731,7 @@ mapM_ f = go
731 in foldStream defState yieldk single stop m1
731 in foldStream defState yieldk single stop m1
732
732
733{-# INLINE mapM #-}
733{-# INLINE mapM #-}
734−mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
734+mapM :: Monad m => (a -> m b) -> StreamK m a -> StreamK m b
735mapM = mapMWith consM
735mapM = mapMWith consM
736
736
737------------------------------------------------------------------------------
737------------------------------------------------------------------------------
@@ -739,13 +739,13 @@ mapM = mapMWith consM
739------------------------------------------------------------------------------
739------------------------------------------------------------------------------
740
740
741{-# INLINABLE toList #-}
741{-# INLINABLE toList #-}
742−toList :: Monad m => Stream m a -> m [a]
742+toList :: Monad m => StreamK m a -> m [a]
743toList = foldr (:) []
743toList = foldr (:) []
744
744
745-- Based on suggestions by David Feuer and Pranay Sashank
745-- Based on suggestions by David Feuer and Pranay Sashank
746{-# INLINE hoist #-}
746{-# INLINE hoist #-}
747hoist :: (Monad m, Monad n)
747hoist :: (Monad m, Monad n)
748− => (forall x. m x -> n x) -> Stream m a -> Stream n a
748+ => (forall x. m x -> n x) -> StreamK m a -> StreamK n a
749hoist f str =
749hoist f str =
750 mkStream $ \st yld sng stp ->
750 mkStream $ \st yld sng stp ->
751 let single = return . sng
751 let single = return . sng
@@ -759,7 +759,7 @@ hoist f str =
759-------------------------------------------------------------------------------
759-------------------------------------------------------------------------------
760
760
761{-# INLINE scanlx' #-}
761{-# INLINE scanlx' #-}
762−scanlx' :: (x -> a -> x) -> x -> (x -> b) -> Stream m a -> Stream m b
762+scanlx' :: (x -> a -> x) -> x -> (x -> b) -> StreamK m a -> StreamK m b
763scanlx' step begin done m =
763scanlx' step begin done m =
764 cons (done begin) $ go m begin
764 cons (done begin) $ go m begin
765 where
765 where
@@ -771,7 +771,7 @@ scanlx' step begin done m =
771 in foldStream (adaptState st) yieldk single stp m1
771 in foldStream (adaptState st) yieldk single stp m1
772
772
773{-# INLINE scanl' #-}
773{-# INLINE scanl' #-}
774−scanl' :: (b -> a -> b) -> b -> Stream m a -> Stream m b
774+scanl' :: (b -> a -> b) -> b -> StreamK m a -> StreamK m b
775scanl' step begin = scanlx' step begin id
775scanl' step begin = scanlx' step begin id
776
776
777-------------------------------------------------------------------------------
777-------------------------------------------------------------------------------
@@ -779,7 +779,7 @@ scanl' step begin = scanlx' step begin id
779-------------------------------------------------------------------------------
779-------------------------------------------------------------------------------
780
780
781{-# INLINE filter #-}
781{-# INLINE filter #-}
782−filter :: (a -> Bool) -> Stream m a -> Stream m a
782+filter :: (a -> Bool) -> StreamK m a -> StreamK m a
783filter p = go
783filter p = go
784 where
784 where
785 go m1 = mkStream $ \st yld sng stp ->
785 go m1 = mkStream $ \st yld sng stp ->
@@ -790,7 +790,7 @@ filter p = go
790 in foldStream st yieldk single stp m1
790 in foldStream st yieldk single stp m1
791
791
792{-# INLINE take #-}
792{-# INLINE take #-}
793−take :: Int -> Stream m a -> Stream m a
793+take :: Int -> StreamK m a -> StreamK m a
794take = go
794take = go
795 where
795 where
796 go n1 m1 = mkStream $ \st yld sng stp ->
796 go n1 m1 = mkStream $ \st yld sng stp ->
@@ -800,7 +800,7 @@ take = go
800 else foldStream st yieldk sng stp m1
800 else foldStream st yieldk sng stp m1
801
801
802{-# INLINE takeWhile #-}
802{-# INLINE takeWhile #-}
803−takeWhile :: (a -> Bool) -> Stream m a -> Stream m a
803+takeWhile :: (a -> Bool) -> StreamK m a -> StreamK m a
804takeWhile p = go
804takeWhile p = go
805 where
805 where
806 go m1 = mkStream $ \st yld sng stp ->
806 go m1 = mkStream $ \st yld sng stp ->
@@ -811,7 +811,7 @@ takeWhile p = go
811 in foldStream st yieldk single stp m1
811 in foldStream st yieldk single stp m1
812
812
813{-# INLINE drop #-}
813{-# INLINE drop #-}
814−drop :: Int -> Stream m a -> Stream m a
814+drop :: Int -> StreamK m a -> StreamK m a
815drop n m = unShare (go n m)
815drop n m = unShare (go n m)
816 where
816 where
817 go n1 m1 = mkStream $ \st yld sng stp ->
817 go n1 m1 = mkStream $ \st yld sng stp ->
@@ -823,7 +823,7 @@ drop n m = unShare (go n m)
823 else foldStreamShared st yieldk single stp m1
823 else foldStreamShared st yieldk single stp m1
824
824
825{-# INLINE dropWhile #-}
825{-# INLINE dropWhile #-}
826−dropWhile :: (a -> Bool) -> Stream m a -> Stream m a
826+dropWhile :: (a -> Bool) -> StreamK m a -> StreamK m a
827dropWhile p = go
827dropWhile p = go
828 where
828 where
829 go m1 = mkStream $ \st yld sng stp ->
829 go m1 = mkStream $ \st yld sng stp ->
@@ -840,7 +840,7 @@ dropWhile p = go
840-- Be careful when modifying this, this uses a consM (|:) deliberately to allow
840-- Be careful when modifying this, this uses a consM (|:) deliberately to allow
841-- other stream types to overload it.
841-- other stream types to overload it.
842{-# INLINE sequence #-}
842{-# INLINE sequence #-}
843−sequence :: Monad m => Stream m (m a) -> Stream m a
843+sequence :: Monad m => StreamK m (m a) -> StreamK m a
844sequence = go
844sequence = go
845 where
845 where
846 go m1 = mkStream $ \st yld sng stp ->
846 go m1 = mkStream $ \st yld sng stp ->
@@ -853,7 +853,7 @@ sequence = go
853-------------------------------------------------------------------------------
853-------------------------------------------------------------------------------
854
854
855{-# INLINE intersperseM #-}
855{-# INLINE intersperseM #-}
856−intersperseM :: Monad m => m a -> Stream m a -> Stream m a
856+intersperseM :: Monad m => m a -> StreamK m a -> StreamK m a
857intersperseM a = prependingStart
857intersperseM a = prependingStart
858 where
858 where
859 prependingStart m1 = mkStream $ \st yld sng stp ->
859 prependingStart m1 = mkStream $ \st yld sng stp ->
@@ -868,11 +868,11 @@ intersperseM a = prependingStart
868 in foldStream st yieldk single stp m2
868 in foldStream st yieldk single stp m2
869
869
870{-# INLINE intersperse #-}
870{-# INLINE intersperse #-}
871−intersperse :: Monad m => a -> Stream m a -> Stream m a
871+intersperse :: Monad m => a -> StreamK m a -> StreamK m a
872intersperse a = intersperseM (return a)
872intersperse a = intersperseM (return a)
873
873
874{-# INLINE insertBy #-}
874{-# INLINE insertBy #-}
875−insertBy :: (a -> a -> Ordering) -> a -> Stream m a -> Stream m a
875+insertBy :: (a -> a -> Ordering) -> a -> StreamK m a -> StreamK m a
876insertBy cmp x = go
876insertBy cmp x = go
877 where
877 where
878 go m1 = mkStream $ \st yld _ _ ->
878 go m1 = mkStream $ \st yld _ _ ->
@@ -890,7 +890,7 @@ insertBy cmp x = go
890------------------------------------------------------------------------------
890------------------------------------------------------------------------------
891
891
892{-# INLINE deleteBy #-}
892{-# INLINE deleteBy #-}
893−deleteBy :: (a -> a -> Bool) -> a -> Stream m a -> Stream m a
893+deleteBy :: (a -> a -> Bool) -> a -> StreamK m a -> StreamK m a
894deleteBy eq x = go
894deleteBy eq x = go
895 where
895 where
896 go m1 = mkStream $ \st yld sng stp ->
896 go m1 = mkStream $ \st yld sng stp ->
@@ -905,7 +905,7 @@ deleteBy eq x = go
905-------------------------------------------------------------------------------
905-------------------------------------------------------------------------------
906
906
907{-# INLINE mapMaybe #-}
907{-# INLINE mapMaybe #-}
908−mapMaybe :: (a -> Maybe b) -> Stream m a -> Stream m b
908+mapMaybe :: (a -> Maybe b) -> StreamK m a -> StreamK m b
909mapMaybe f = go
909mapMaybe f = go
910 where
910 where
911 go m1 = mkStream $ \st yld sng stp ->
911 go m1 = mkStream $ \st yld sng stp ->
@@ -923,7 +923,7 @@ mapMaybe f = go
923--
923--
924-- @since 0.1.0
924-- @since 0.1.0
925{-# INLINE zipWith #-}
925{-# INLINE zipWith #-}
926−zipWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
926+zipWith :: Monad m => (a -> b -> c) -> StreamK m a -> StreamK m b -> StreamK m c
927zipWith f = zipWithM (\a b -> return (f a b))
927zipWith f = zipWithM (\a b -> return (f a b))
928
928
929-- | Zip two streams serially using a monadic zipping function.
929-- | Zip two streams serially using a monadic zipping function.
@@ -931,7 +931,7 @@ zipWith f = zipWithM (\a b -> return (f a b))
931-- @since 0.1.0
931-- @since 0.1.0
932{-# INLINE zipWithM #-}
932{-# INLINE zipWithM #-}
933zipWithM :: Monad m =>
933zipWithM :: Monad m =>
934− (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
934+ (a -> b -> m c) -> StreamK m a -> StreamK m b -> StreamK m c
935zipWithM f = go
935zipWithM f = go
936
936
937 where
937 where
@@ -951,7 +951,7 @@ zipWithM f = go
951
951
952{-# INLINE mergeByM #-}
952{-# INLINE mergeByM #-}
953mergeByM :: Monad m =>
953mergeByM :: Monad m =>
954− (a -> a -> m Ordering) -> Stream m a -> Stream m a -> Stream m a
954+ (a -> a -> m Ordering) -> StreamK m a -> StreamK m a -> StreamK m a
955mergeByM cmp = go
955mergeByM cmp = go
956
956
957 where
957 where
@@ -1019,7 +1019,7 @@ mergeByM cmp = go
1019 in foldStream st yield single stop mx
1019 in foldStream st yield single stop mx
1020
1020
1021{-# INLINE mergeBy #-}
1021{-# INLINE mergeBy #-}
1022−mergeBy :: (a -> a -> Ordering) -> Stream m a -> Stream m a -> Stream m a
1022+mergeBy :: (a -> a -> Ordering) -> StreamK m a -> StreamK m a -> StreamK m a
1023-- XXX GHC: This has slightly worse performance than replacing "r <- cmp x y"
1023-- XXX GHC: This has slightly worse performance than replacing "r <- cmp x y"
1024-- with "let r = cmp x y" in the monadic version. The definition below is
1024-- with "let r = cmp x y" in the monadic version. The definition below is
1025-- exactly the same as mergeByM except this change.
1025-- exactly the same as mergeByM except this change.
@@ -1087,7 +1087,7 @@ mergeBy cmp = go
1087------------------------------------------------------------------------------
1087------------------------------------------------------------------------------
1088
1088
1089{-# INLINE the #-}
1089{-# INLINE the #-}
1090−the :: (Eq a, Monad m) => Stream m a -> m (Maybe a)
1090+the :: (Eq a, Monad m) => StreamK m a -> m (Maybe a)
1091the m = do
1091the m = do
1092 r <- uncons m
1092 r <- uncons m
1093 case r of
1093 case r of
@@ -1105,7 +1105,7 @@ the m = do
1105-- Alternative & MonadPlus
1105-- Alternative & MonadPlus
1106------------------------------------------------------------------------------
1106------------------------------------------------------------------------------
1107
1107
1108−_alt :: Stream m a -> Stream m a -> Stream m a
1108+_alt :: StreamK m a -> StreamK m a -> StreamK m a
1109_alt m1 m2 = mkStream $ \st yld sng stp ->
1109_alt m1 m2 = mkStream $ \st yld sng stp ->
1110 let stop = foldStream st yld sng stp m2
1110 let stop = foldStream st yld sng stp m2
1111 in foldStream st yld sng stop m1
1111 in foldStream st yld sng stop m1
@@ -1118,7 +1118,7 @@ _alt m1 m2 = mkStream $ \st yld sng stp ->
1118-- XXX handle and test cross thread state transfer
1118-- XXX handle and test cross thread state transfer
1119withCatchError
1119withCatchError
1120 :: MonadError e m
1120 :: MonadError e m
1121− => Stream m a -> (e -> Stream m a) -> Stream m a
1121+ => StreamK m a -> (e -> StreamK m a) -> StreamK m a
1122withCatchError m h =
1122withCatchError m h =
1123 mkStream $ \_ stp sng yld ->
1123 mkStream $ \_ stp sng yld ->
1124 let run x = unStream x Nothing stp sng yieldk
1124 let run x = unStream x Nothing stp sng yieldk
@@ -1150,8 +1150,8 @@ splitAt n ls
1150parseDBreak
1150parseDBreak
1151 :: Monad m
1151 :: Monad m
1152 => PR.Parser a m b
1152 => PR.Parser a m b
1153− -> Stream m a
1153+ -> StreamK m a
1154− -> m (Either ParseError b, Stream m a)
1154+ -> m (Either ParseError b, StreamK m a)
1155parseDBreak (PR.Parser pstep initial extract) stream = do
1155parseDBreak (PR.Parser pstep initial extract) stream = do
1156 res <- initial
1156 res <- initial
1157 case res of
1157 case res of
@@ -1238,7 +1238,7 @@ parseDBreak (PR.Parser pstep initial extract) stream = do
1238-- and convert ParserD to ParserK for element parsing using StreamK.
1238-- and convert ParserD to ParserK for element parsing using StreamK.
1239{-# INLINE parseD #-}
1239{-# INLINE parseD #-}
1240parseD :: Monad m =>
1240parseD :: Monad m =>
1241− Parser.Parser a m b -> Stream m a -> m (Either ParseError b)
1241+ Parser.Parser a m b -> StreamK m a -> m (Either ParseError b)
1242parseD f = fmap fst . parseDBreak f
1242parseD f = fmap fst . parseDBreak f
1243
1243
1244-------------------------------------------------------------------------------
1244-------------------------------------------------------------------------------
@@ -1373,7 +1373,7 @@ parseBreakChunks parser input = do
1373
1373
1374{-# INLINE parseChunks #-}
1374{-# INLINE parseChunks #-}
1375parseChunks :: (Monad m, Unbox a) =>
1375parseChunks :: (Monad m, Unbox a) =>
1376− ParserK.Parser a m b -> Stream m (Array a) -> m (Either ParseError b)
1376+ ParserK.Parser a m b -> StreamK m (Array a) -> m (Either ParseError b)
1377parseChunks f = fmap fst . parseBreakChunks f
1377parseChunks f = fmap fst . parseBreakChunks f
1378
1378
1379-------------------------------------------------------------------------------
1379-------------------------------------------------------------------------------
@@ -1393,7 +1393,7 @@ parseChunks f = fmap fst . parseBreakChunks f
1393-- /O(n) space/
1393-- /O(n) space/
1394--
1394--
1395{-# INLINE sortBy #-}
1395{-# INLINE sortBy #-}
1396−sortBy :: Monad m => (a -> a -> Ordering) -> Stream m a -> Stream m a
1396+sortBy :: Monad m => (a -> a -> Ordering) -> StreamK m a -> StreamK m a
1397-- sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.fromPure
1397-- sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.fromPure
1398sortBy cmp =
1398sortBy cmp =
1399 let p =
1399 let p =
core/src/Streamly/Internal/Data/Stream/StreamK/Transformer.hs+5−5
@@ -19,14 +19,14 @@ where
19import Control.Monad.Trans.Class (MonadTrans(lift))
19import Control.Monad.Trans.Class (MonadTrans(lift))
20import Control.Monad.Trans.State.Strict (StateT)
20import Control.Monad.Trans.State.Strict (StateT)
21import Streamly.Internal.Data.Stream.StreamK
21import Streamly.Internal.Data.Stream.StreamK
22− (Stream, nil, cons, uncons, concatEffect)
22+ (StreamK, nil, cons, uncons, concatEffect)
23
23
24import qualified Control.Monad.Trans.State.Strict as State
24import qualified Control.Monad.Trans.State.Strict as State
25
25
26-- | Lazy left fold to an arbitrary transformer monad.
26-- | Lazy left fold to an arbitrary transformer monad.
27{-# INLINE foldlT #-}
27{-# INLINE foldlT #-}
28foldlT :: (Monad m, Monad (s m), MonadTrans s)
28foldlT :: (Monad m, Monad (s m), MonadTrans s)
29− => (s m b -> a -> s m b) -> s m b -> Stream m a -> s m b
29+ => (s m b -> a -> s m b) -> s m b -> StreamK m a -> s m b
30foldlT step = go
30foldlT step = go
31 where
31 where
32 go acc m1 = do
32 go acc m1 = do
@@ -38,7 +38,7 @@ foldlT step = go
38-- | Right associative fold to an arbitrary transformer monad.
38-- | Right associative fold to an arbitrary transformer monad.
39{-# INLINE foldrT #-}
39{-# INLINE foldrT #-}
40foldrT :: (Monad m, Monad (s m), MonadTrans s)
40foldrT :: (Monad m, Monad (s m), MonadTrans s)
41− => (a -> s m b -> s m b) -> s m b -> Stream m a -> s m b
41+ => (a -> s m b -> s m b) -> s m b -> StreamK m a -> s m b
42foldrT step final = go
42foldrT step final = go
43 where
43 where
44 go m1 = do
44 go m1 = do
@@ -52,7 +52,7 @@ foldrT step final = go
52------------------------------------------------------------------------------
52------------------------------------------------------------------------------
53
53
54{-# INLINE evalStateT #-}
54{-# INLINE evalStateT #-}
55−evalStateT :: Monad m => m s -> Stream (StateT s m) a -> Stream m a
55+evalStateT :: Monad m => m s -> StreamK (StateT s m) a -> StreamK m a
56evalStateT = go
56evalStateT = go
57
57
58 where
58 where
@@ -66,7 +66,7 @@ evalStateT = go
66
66
67{-# INLINE liftInner #-}
67{-# INLINE liftInner #-}
68liftInner :: (Monad m, MonadTrans t, Monad (t m)) =>
68liftInner :: (Monad m, MonadTrans t, Monad (t m)) =>
69− Stream m a -> Stream (t m) a
69+ StreamK m a -> StreamK (t m) a
70liftInner = go
70liftInner = go
71
71
72 where
72 where
core/src/Streamly/Internal/Data/Stream/StreamK/Type.hs+201−200
@@ -15,8 +15,8 @@
15module Streamly.Internal.Data.Stream.StreamK.Type
15module Streamly.Internal.Data.Stream.StreamK.Type
16 (
16 (
17 -- * StreamK type
17 -- * StreamK type
18− Stream (..) -- XXX stop exporting this
18+ Stream
19− , StreamK
19+ , StreamK (..)
20
20
21 -- * CrossStreamK type wrapper
21 -- * CrossStreamK type wrapper
22 , CrossStreamK
22 , CrossStreamK
@@ -181,7 +181,7 @@ import Prelude hiding
181-- direct style type:
181-- direct style type:
182--
182--
183-- @
183-- @
184−-- data Stream m a = Stop | Singleton a | Yield a (Stream m a)
184+-- data StreamK m a = Stop | Singleton a | Yield a (StreamK m a)
185-- @
185-- @
186--
186--
187-- To facilitate parallel composition we maintain a local state in an 'SVar'
187-- To facilitate parallel composition we maintain a local state in an 'SVar'
@@ -203,24 +203,25 @@ import Prelude hiding
203--
203--
204-- >>> (<>) = Stream.append
204-- >>> (<>) = Stream.append
205--
205--
206−type StreamK = Stream
206+{-# DEPRECATED Stream "Please use StreamK instead." #-}
207+type Stream = StreamK
207
208
208−newtype Stream m a =
209+newtype StreamK m a =
209 MkStream (forall r.
210 MkStream (forall r.
210− State Stream m a -- state
211+ State StreamK m a -- state
211− -> (a -> Stream m a -> m r) -- yield
212+ -> (a -> StreamK m a -> m r) -- yield
212 -> (a -> m r) -- singleton
213 -> (a -> m r) -- singleton
213 -> m r -- stop
214 -> m r -- stop
214 -> m r
215 -> m r
215 )
216 )
216
217
217mkStream
218mkStream
218− :: (forall r. State Stream m a
219+ :: (forall r. State StreamK m a
219− -> (a -> Stream m a -> m r)
220+ -> (a -> StreamK m a -> m r)
220 -> (a -> m r)
221 -> (a -> m r)
221 -> m r
222 -> m r
222 -> m r)
223 -> m r)
223− -> Stream m a
224+ -> StreamK m a
224mkStream = MkStream
225mkStream = MkStream
225
226
226-- | A terminal function that has no continuation to follow.
227-- | A terminal function that has no continuation to follow.
@@ -236,16 +237,16 @@ _wrapM :: Monad m => m a -> YieldK m a
236_wrapM m = (m >>=)
237_wrapM m = (m >>=)
237
238
238-- | Make an empty stream from a stop function.
239-- | Make an empty stream from a stop function.
239−fromStopK :: StopK m -> Stream m a
240+fromStopK :: StopK m -> StreamK m a
240fromStopK k = mkStream $ \_ _ _ stp -> k stp
241fromStopK k = mkStream $ \_ _ _ stp -> k stp
241
242
242-- | Make a singleton stream from a callback function. The callback function
243-- | Make a singleton stream from a callback function. The callback function
243-- calls the one-shot yield continuation to yield an element.
244-- calls the one-shot yield continuation to yield an element.
244−fromYieldK :: YieldK m a -> Stream m a
245+fromYieldK :: YieldK m a -> StreamK m a
245fromYieldK k = mkStream $ \_ _ sng _ -> k sng
246fromYieldK k = mkStream $ \_ _ sng _ -> k sng
246
247
247-- | Add a yield function at the head of the stream.
248-- | Add a yield function at the head of the stream.
248−consK :: YieldK m a -> Stream m a -> Stream m a
249+consK :: YieldK m a -> StreamK m a -> StreamK m a
249consK k r = mkStream $ \_ yld _ _ -> k (`yld` r)
250consK k r = mkStream $ \_ yld _ _ -> k (`yld` r)
250
251
251-- XXX Build a stream from a repeating callback function.
252-- XXX Build a stream from a repeating callback function.
@@ -274,7 +275,7 @@ infixr 5 `cons`
274-- >>> cons x xs = return x `StreamK.consM` xs
275-- >>> cons x xs = return x `StreamK.consM` xs
275--
276--
276{-# INLINE_NORMAL cons #-}
277{-# INLINE_NORMAL cons #-}
277−cons :: a -> Stream m a -> Stream m a
278+cons :: a -> StreamK m a -> StreamK m a
278cons a r = mkStream $ \_ yield _ _ -> yield a r
279cons a r = mkStream $ \_ yield _ _ -> yield a r
279
280
280infixr 5 .:
281infixr 5 .:
@@ -288,7 +289,7 @@ infixr 5 .:
288--
289--
289-- @since 0.1.1
290-- @since 0.1.1
290{-# INLINE (.:) #-}
291{-# INLINE (.:) #-}
291−(.:) :: a -> Stream m a -> Stream m a
292+(.:) :: a -> StreamK m a -> StreamK m a
292(.:) = cons
293(.:) = cons
293
294
294-- | A stream that terminates without producing any output or side effect.
295-- | A stream that terminates without producing any output or side effect.
@@ -297,7 +298,7 @@ infixr 5 .:
297-- []
298-- []
298--
299--
299{-# INLINE_NORMAL nil #-}
300{-# INLINE_NORMAL nil #-}
300−nil :: Stream m a
301+nil :: StreamK m a
301nil = mkStream $ \_ _ _ stp -> stp
302nil = mkStream $ \_ _ _ stp -> stp
302
303
303-- | A stream that terminates without producing any output, but produces a side
304-- | A stream that terminates without producing any output, but produces a side
@@ -309,7 +310,7 @@ nil = mkStream $ \_ _ _ stp -> stp
309--
310--
310-- /Pre-release/
311-- /Pre-release/
311{-# INLINE_NORMAL nilM #-}
312{-# INLINE_NORMAL nilM #-}
312−nilM :: Applicative m => m b -> Stream m a
313+nilM :: Applicative m => m b -> StreamK m a
313nilM m = mkStream $ \_ _ _ stp -> m *> stp
314nilM m = mkStream $ \_ _ _ stp -> m *> stp
314
315
315-- | Create a singleton stream from a pure value.
316-- | Create a singleton stream from a pure value.
@@ -319,7 +320,7 @@ nilM m = mkStream $ \_ _ _ stp -> m *> stp
319-- >>> fromPure = StreamK.fromEffect . pure
320-- >>> fromPure = StreamK.fromEffect . pure
320--
321--
321{-# INLINE_NORMAL fromPure #-}
322{-# INLINE_NORMAL fromPure #-}
322−fromPure :: a -> Stream m a
323+fromPure :: a -> StreamK m a
323fromPure a = mkStream $ \_ _ single _ -> single a
324fromPure a = mkStream $ \_ _ single _ -> single a
324
325
325-- | Create a singleton stream from a monadic action.
326-- | Create a singleton stream from a monadic action.
@@ -330,7 +331,7 @@ fromPure a = mkStream $ \_ _ single _ -> single a
330-- hello
331-- hello
331--
332--
332{-# INLINE_NORMAL fromEffect #-}
333{-# INLINE_NORMAL fromEffect #-}
333−fromEffect :: Monad m => m a -> Stream m a
334+fromEffect :: Monad m => m a -> StreamK m a
334fromEffect m = mkStream $ \_ _ single _ -> m >>= single
335fromEffect m = mkStream $ \_ _ single _ -> m >>= single
335
336
336infixr 5 `consM`
337infixr 5 `consM`
@@ -356,14 +357,14 @@ infixr 5 `consM`
356-- >>> consM x xs = StreamK.fromEffect x `StreamK.append` xs
357-- >>> consM x xs = StreamK.fromEffect x `StreamK.append` xs
357--
358--
358{-# INLINE consM #-}
359{-# INLINE consM #-}
359−{-# SPECIALIZE consM :: IO a -> Stream IO a -> Stream IO a #-}
360+{-# SPECIALIZE consM :: IO a -> StreamK IO a -> StreamK IO a #-}
360−consM :: Monad m => m a -> Stream m a -> Stream m a
361+consM :: Monad m => m a -> StreamK m a -> StreamK m a
361consM m r = MkStream $ \_ yld _ _ -> m >>= (`yld` r)
362consM m r = MkStream $ \_ yld _ _ -> m >>= (`yld` r)
362
363
363-- XXX specialize to IO?
364-- XXX specialize to IO?
364{-# INLINE consMBy #-}
365{-# INLINE consMBy #-}
365consMBy :: Monad m =>
366consMBy :: Monad m =>
366− (Stream m a -> Stream m a -> Stream m a) -> m a -> Stream m a -> Stream m a
367+ (StreamK m a -> StreamK m a -> StreamK m a) -> m a -> StreamK m a -> StreamK m a
367consMBy f m r = fromEffect m `f` r
368consMBy f m r = fromEffect m `f` r
368
369
369------------------------------------------------------------------------------
370------------------------------------------------------------------------------
@@ -375,11 +376,11 @@ consMBy f m r = fromEffect m `f` r
375-- SVar passed via the State.
376-- SVar passed via the State.
376{-# INLINE_EARLY foldStreamShared #-}
377{-# INLINE_EARLY foldStreamShared #-}
377foldStreamShared
378foldStreamShared
378− :: State Stream m a
379+ :: State StreamK m a
379− -> (a -> Stream m a -> m r)
380+ -> (a -> StreamK m a -> m r)
380 -> (a -> m r)
381 -> (a -> m r)
381 -> m r
382 -> m r
382− -> Stream m a
383+ -> StreamK m a
383 -> m r
384 -> m r
384foldStreamShared s yield single stop (MkStream k) = k s yield single stop
385foldStreamShared s yield single stop (MkStream k) = k s yield single stop
385
386
@@ -388,11 +389,11 @@ foldStreamShared s yield single stop (MkStream k) = k s yield single stop
388-- passed via State.
389-- passed via State.
389{-# INLINE foldStream #-}
390{-# INLINE foldStream #-}
390foldStream
391foldStream
391− :: State Stream m a
392+ :: State StreamK m a
392− -> (a -> Stream m a -> m r)
393+ -> (a -> StreamK m a -> m r)
393 -> (a -> m r)
394 -> (a -> m r)
394 -> m r
395 -> m r
395− -> Stream m a
396+ -> StreamK m a
396 -> m r
397 -> m r
397foldStream s yield single stop (MkStream k) =
398foldStream s yield single stop (MkStream k) =
398 k (adaptState s) yield single stop
399 k (adaptState s) yield single stop
@@ -409,16 +410,16 @@ foldStream s yield single stop (MkStream k) =
409--
410--
410{-# INLINE foldrSWith #-}
411{-# INLINE foldrSWith #-}
411foldrSWith ::
412foldrSWith ::
412− (forall r. State Stream m b
413+ (forall r. State StreamK m b
413− -> (b -> Stream m b -> m r)
414+ -> (b -> StreamK m b -> m r)
414 -> (b -> m r)
415 -> (b -> m r)
415 -> m r
416 -> m r
416− -> Stream m b
417+ -> StreamK m b
417 -> m r)
418 -> m r)
418− -> (a -> Stream m b -> Stream m b)
419+ -> (a -> StreamK m b -> StreamK m b)
419− -> Stream m b
420+ -> StreamK m b
420− -> Stream m a
421+ -> StreamK m a
421− -> Stream m b
422+ -> StreamK m b
422foldrSWith f step final m = go m
423foldrSWith f step final m = go m
423 where
424 where
424 go m1 = mkStream $ \st yld sng stp ->
425 go m1 = mkStream $ \st yld sng stp ->
@@ -438,10 +439,10 @@ foldrSWith f step final m = go m
438-- | Fold sharing the SVar state within the reconstructed stream
439-- | Fold sharing the SVar state within the reconstructed stream
439{-# INLINE_NORMAL foldrSShared #-}
440{-# INLINE_NORMAL foldrSShared #-}
440foldrSShared ::
441foldrSShared ::
441− (a -> Stream m b -> Stream m b)
442+ (a -> StreamK m b -> StreamK m b)
442− -> Stream m b
443+ -> StreamK m b
443− -> Stream m a
444+ -> StreamK m a
444− -> Stream m b
445+ -> StreamK m b
445foldrSShared = foldrSWith foldStreamShared
446foldrSShared = foldrSWith foldStreamShared
446
447
447-- XXX consM is a typeclass method, therefore rewritten already. Instead maybe
448-- XXX consM is a typeclass method, therefore rewritten already. Instead maybe
@@ -477,17 +478,17 @@ foldrSShared = foldrSWith foldStreamShared
477-- Map (+2) on odd elements and filter out the even elements:
478-- Map (+2) on odd elements and filter out the even elements:
478--
479--
479-- >>> step x xs = if odd x then (x + 2) `StreamK.cons` xs else xs
480-- >>> step x xs = if odd x then (x + 2) `StreamK.cons` xs else xs
480−-- >>> input = StreamK.fromStream (Stream.fromList [1..5]) :: Stream IO Int
481+-- >>> input = StreamK.fromStream (Stream.fromList [1..5]) :: StreamK IO Int
481-- >>> Stream.fold Fold.toList $ StreamK.toStream $ StreamK.foldrS step StreamK.nil input
482-- >>> Stream.fold Fold.toList $ StreamK.toStream $ StreamK.foldrS step StreamK.nil input
482-- [3,5,7]
483-- [3,5,7]
483--
484--
484-- /Pre-release/
485-- /Pre-release/
485{-# INLINE_NORMAL foldrS #-}
486{-# INLINE_NORMAL foldrS #-}
486foldrS ::
487foldrS ::
487− (a -> Stream m b -> Stream m b)
488+ (a -> StreamK m b -> StreamK m b)
488− -> Stream m b
489+ -> StreamK m b
489− -> Stream m a
490+ -> StreamK m a
490− -> Stream m b
491+ -> StreamK m b
491foldrS = foldrSWith foldStream
492foldrS = foldrSWith foldStream
492
493
493{-# RULES "foldrS/id" foldrS cons nil = \x -> x #-}
494{-# RULES "foldrS/id" foldrS cons nil = \x -> x #-}
@@ -505,16 +506,16 @@ foldrS = foldrSWith foldStream
505
506
506{-# INLINE foldrSMWith #-}
507{-# INLINE foldrSMWith #-}
507foldrSMWith :: Monad m
508foldrSMWith :: Monad m
508− => (forall r. State Stream m b
509+ => (forall r. State StreamK m b
509− -> (b -> Stream m b -> m r)
510+ -> (b -> StreamK m b -> m r)
510 -> (b -> m r)
511 -> (b -> m r)
511 -> m r
512 -> m r
512− -> Stream m b
513+ -> StreamK m b
513 -> m r)
514 -> m r)
514− -> (m a -> Stream m b -> Stream m b)
515+ -> (m a -> StreamK m b -> StreamK m b)
515− -> Stream m b
516+ -> StreamK m b
516− -> Stream m a
517+ -> StreamK m a
517− -> Stream m b
518+ -> StreamK m b
518foldrSMWith f step final m = go m
519foldrSMWith f step final m = go m
519 where
520 where
520 go m1 = mkStream $ \st yld sng stp ->
521 go m1 = mkStream $ \st yld sng stp ->
@@ -526,10 +527,10 @@ foldrSMWith f step final m = go m
526
527
527{-# INLINE_NORMAL foldrSM #-}
528{-# INLINE_NORMAL foldrSM #-}
528foldrSM :: Monad m
529foldrSM :: Monad m
529− => (m a -> Stream m b -> Stream m b)
530+ => (m a -> StreamK m b -> StreamK m b)
530− -> Stream m b
531+ -> StreamK m b
531− -> Stream m a
532+ -> StreamK m a
532− -> Stream m b
533+ -> StreamK m b
533foldrSM = foldrSMWith foldStream
534foldrSM = foldrSMWith foldStream
534
535
535-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
536-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
@@ -541,10 +542,10 @@ foldrSM = foldrSMWith foldStream
541-- Like foldrSM but sharing the SVar state within the recostructed stream.
542-- Like foldrSM but sharing the SVar state within the recostructed stream.
542{-# INLINE_NORMAL foldrSMShared #-}
543{-# INLINE_NORMAL foldrSMShared #-}
543foldrSMShared :: Monad m
544foldrSMShared :: Monad m
544− => (m a -> Stream m b -> Stream m b)
545+ => (m a -> StreamK m b -> StreamK m b)
545− -> Stream m b
546+ -> StreamK m b
546− -> Stream m a
547+ -> StreamK m a
547− -> Stream m b
548+ -> StreamK m b
548foldrSMShared = foldrSMWith foldStreamShared
549foldrSMShared = foldrSMWith foldStreamShared
549
550
550-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
551-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
@@ -560,7 +561,7 @@ foldrSMShared = foldrSMWith foldStreamShared
560-------------------------------------------------------------------------------
561-------------------------------------------------------------------------------
561
562
562{-# INLINE_NORMAL build #-}
563{-# INLINE_NORMAL build #-}
563−build :: forall m a. (forall b. (a -> b -> b) -> b -> b) -> Stream m a
564+build :: forall m a. (forall b. (a -> b -> b) -> b -> b) -> StreamK m a
564build g = g cons nil
565build g = g cons nil
565
566
566{-# RULES "foldrM/build"
567{-# RULES "foldrM/build"
@@ -586,45 +587,45 @@ build g = g cons nil
586-- build a stream by applying cons and nil to a build function
587-- build a stream by applying cons and nil to a build function
587{-# INLINE_NORMAL buildS #-}
588{-# INLINE_NORMAL buildS #-}
588buildS ::
589buildS ::
589− ((a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
590+ ((a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
590− -> Stream m a
591+ -> StreamK m a
591buildS g = g cons nil
592buildS g = g cons nil
592
593
593{-# RULES "foldrS/buildS"
594{-# RULES "foldrS/buildS"
594 forall k z
595 forall k z
595− (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
596+ (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
596 foldrS k z (buildS g) = g k z #-}
597 foldrS k z (buildS g) = g k z #-}
597
598
598{-# RULES "foldrS/cons/buildS"
599{-# RULES "foldrS/cons/buildS"
599 forall k z x
600 forall k z x
600− (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
601+ (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
601 foldrS k z (x `cons` buildS g) = k x (g k z) #-}
602 foldrS k z (x `cons` buildS g) = k x (g k z) #-}
602
603
603{-# RULES "foldrSShared/buildS"
604{-# RULES "foldrSShared/buildS"
604 forall k z
605 forall k z
605− (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
606+ (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
606 foldrSShared k z (buildS g) = g k z #-}
607 foldrSShared k z (buildS g) = g k z #-}
607
608
608{-# RULES "foldrSShared/cons/buildS"
609{-# RULES "foldrSShared/cons/buildS"
609 forall k z x
610 forall k z x
610− (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
611+ (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
611 foldrSShared k z (x `cons` buildS g) = k x (g k z) #-}
612 foldrSShared k z (x `cons` buildS g) = k x (g k z) #-}
612
613
613-- build a stream by applying consM and nil to a build function
614-- build a stream by applying consM and nil to a build function
614{-# INLINE_NORMAL buildSM #-}
615{-# INLINE_NORMAL buildSM #-}
615buildSM :: Monad m
616buildSM :: Monad m
616− => ((m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
617+ => ((m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
617− -> Stream m a
618+ -> StreamK m a
618buildSM g = g consM nil
619buildSM g = g consM nil
619
620
620{-# RULES "foldrSM/buildSM"
621{-# RULES "foldrSM/buildSM"
621 forall k z
622 forall k z
622− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
623+ (g :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
623 foldrSM k z (buildSM g) = g k z #-}
624 foldrSM k z (buildSM g) = g k z #-}
624
625
625{-# RULES "foldrSMShared/buildSM"
626{-# RULES "foldrSMShared/buildSM"
626 forall k z
627 forall k z
627− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
628+ (g :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
628 foldrSMShared k z (buildSM g) = g k z #-}
629 foldrSMShared k z (buildSM g) = g k z #-}
629
630
630-- Disabled because this may not fire as consM is a class Op
631-- Disabled because this may not fire as consM is a class Op
@@ -640,25 +641,25 @@ buildSM g = g consM nil
640-- reconstructing a stream.
641-- reconstructing a stream.
641{-# INLINE_NORMAL buildM #-}
642{-# INLINE_NORMAL buildM #-}
642buildM :: Monad m
643buildM :: Monad m
643− => (forall r. (a -> Stream m a -> m r)
644+ => (forall r. (a -> StreamK m a -> m r)
644 -> (a -> m r)
645 -> (a -> m r)
645 -> m r
646 -> m r
646 -> m r
647 -> m r
647 )
648 )
648− -> Stream m a
649+ -> StreamK m a
649buildM g = mkStream $ \st yld sng stp ->
650buildM g = mkStream $ \st yld sng stp ->
650 g (\a r -> foldStream st yld sng stp (return a `consM` r)) sng stp
651 g (\a r -> foldStream st yld sng stp (return a `consM` r)) sng stp
651
652
652-- | Like 'buildM' but shares the SVar state across computations.
653-- | Like 'buildM' but shares the SVar state across computations.
653{-# INLINE_NORMAL sharedMWith #-}
654{-# INLINE_NORMAL sharedMWith #-}
654sharedMWith :: Monad m
655sharedMWith :: Monad m
655− => (m a -> Stream m a -> Stream m a)
656+ => (m a -> StreamK m a -> StreamK m a)
656− -> (forall r. (a -> Stream m a -> m r)
657+ -> (forall r. (a -> StreamK m a -> m r)
657 -> (a -> m r)
658 -> (a -> m r)
658 -> m r
659 -> m r
659 -> m r
660 -> m r
660 )
661 )
661− -> Stream m a
662+ -> StreamK m a
662sharedMWith cns g = mkStream $ \st yld sng stp ->
663sharedMWith cns g = mkStream $ \st yld sng stp ->
663 g (\a r -> foldStreamShared st yld sng stp (return a `cns` r)) sng stp
664 g (\a r -> foldStreamShared st yld sng stp (return a `cns` r)) sng stp
664
665
@@ -668,50 +669,50 @@ sharedMWith cns g = mkStream $ \st yld sng stp ->
668
669
669{-# INLINE_NORMAL augmentS #-}
670{-# INLINE_NORMAL augmentS #-}
670augmentS ::
671augmentS ::
671− ((a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
672+ ((a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
672− -> Stream m a
673+ -> StreamK m a
673− -> Stream m a
674+ -> StreamK m a
674augmentS g xs = g cons xs
675augmentS g xs = g cons xs
675
676
676{-# RULES "augmentS/nil"
677{-# RULES "augmentS/nil"
677− forall (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
678+ forall (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
678 augmentS g nil = buildS g
679 augmentS g nil = buildS g
679 #-}
680 #-}
680
681
681{-# RULES "foldrS/augmentS"
682{-# RULES "foldrS/augmentS"
682 forall k z xs
683 forall k z xs
683− (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
684+ (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
684 foldrS k z (augmentS g xs) = g k (foldrS k z xs)
685 foldrS k z (augmentS g xs) = g k (foldrS k z xs)
685 #-}
686 #-}
686
687
687{-# RULES "augmentS/buildS"
688{-# RULES "augmentS/buildS"
688− forall (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
689+ forall (g :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
689− (h :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
690+ (h :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
690 augmentS g (buildS h) = buildS (\c n -> g c (h c n))
691 augmentS g (buildS h) = buildS (\c n -> g c (h c n))
691 #-}
692 #-}
692
693
693{-# INLINE_NORMAL augmentSM #-}
694{-# INLINE_NORMAL augmentSM #-}
694augmentSM :: Monad m =>
695augmentSM :: Monad m =>
695− ((m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
696+ ((m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
696− -> Stream m a -> Stream m a
697+ -> StreamK m a -> StreamK m a
697augmentSM g xs = g consM xs
698augmentSM g xs = g consM xs
698
699
699{-# RULES "augmentSM/nil"
700{-# RULES "augmentSM/nil"
700 forall
701 forall
701− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
702+ (g :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
702 augmentSM g nil = buildSM g
703 augmentSM g nil = buildSM g
703 #-}
704 #-}
704
705
705{-# RULES "foldrSM/augmentSM"
706{-# RULES "foldrSM/augmentSM"
706 forall k z xs
707 forall k z xs
707− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
708+ (g :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
708 foldrSM k z (augmentSM g xs) = g k (foldrSM k z xs)
709 foldrSM k z (augmentSM g xs) = g k (foldrSM k z xs)
709 #-}
710 #-}
710
711
711{-# RULES "augmentSM/buildSM"
712{-# RULES "augmentSM/buildSM"
712 forall
713 forall
713− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
714+ (g :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
714− (h :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a).
715+ (h :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
715 augmentSM g (buildSM h) = buildSM (\c n -> g c (h c n))
716 augmentSM g (buildSM h) = buildSM (\c n -> g c (h c n))
716 #-}
717 #-}
717
718
@@ -721,7 +722,7 @@ augmentSM g xs = g consM xs
721
722
722-- | Lazy right fold with a monadic step function.
723-- | Lazy right fold with a monadic step function.
723{-# INLINE_NORMAL foldrM #-}
724{-# INLINE_NORMAL foldrM #-}
724−foldrM :: (a -> m b -> m b) -> m b -> Stream m a -> m b
725+foldrM :: (a -> m b -> m b) -> m b -> StreamK m a -> m b
725foldrM step acc m = go m
726foldrM step acc m = go m
726 where
727 where
727 go m1 =
728 go m1 =
@@ -732,15 +733,15 @@ foldrM step acc m = go m
732
733
733{-# INLINE_NORMAL foldrMKWith #-}
734{-# INLINE_NORMAL foldrMKWith #-}
734foldrMKWith
735foldrMKWith
735− :: (State Stream m a
736+ :: (State StreamK m a
736− -> (a -> Stream m a -> m b)
737+ -> (a -> StreamK m a -> m b)
737 -> (a -> m b)
738 -> (a -> m b)
738 -> m b
739 -> m b
739− -> Stream m a
740+ -> StreamK m a
740 -> m b)
741 -> m b)
741 -> (a -> m b -> m b)
742 -> (a -> m b -> m b)
742 -> m b
743 -> m b
743− -> ((a -> Stream m a -> m b) -> (a -> m b) -> m b -> m b)
744+ -> ((a -> StreamK m a -> m b) -> (a -> m b) -> m b -> m b)
744 -> m b
745 -> m b
745foldrMKWith f step acc = go
746foldrMKWith f step acc = go
746 where
747 where
@@ -760,7 +761,7 @@ foldrMKWith f step acc = go
760-- XXX in which case will foldrM/buildM fusion be useful?
761-- XXX in which case will foldrM/buildM fusion be useful?
761{-# RULES "foldrM/buildM"
762{-# RULES "foldrM/buildM"
762 forall step acc (g :: (forall r.
763 forall step acc (g :: (forall r.
763− (a -> Stream m a -> m r)
764+ (a -> StreamK m a -> m r)
764 -> (a -> m r)
765 -> (a -> m r)
765 -> m r
766 -> m r
766 -> m r
767 -> m r
@@ -771,7 +772,7 @@ foldrMKWith f step acc = go
771{-
772{-
772{-# RULES "foldrM/sharedM"
773{-# RULES "foldrM/sharedM"
773 forall step acc (g :: (forall r.
774 forall step acc (g :: (forall r.
774− (a -> Stream m a -> m r)
775+ (a -> StreamK m a -> m r)
775 -> (a -> m r)
776 -> (a -> m r)
776 -> m r
777 -> m r
777 -> m r
778 -> m r
@@ -792,11 +793,11 @@ foldrMKWith f step acc = go
792-- Note that the accumulator is always evaluated including the initial value.
793-- Note that the accumulator is always evaluated including the initial value.
793{-# INLINE foldlx' #-}
794{-# INLINE foldlx' #-}
794foldlx' :: forall m a b x. Monad m
795foldlx' :: forall m a b x. Monad m
795− => (x -> a -> x) -> x -> (x -> b) -> Stream m a -> m b
796+ => (x -> a -> x) -> x -> (x -> b) -> StreamK m a -> m b
796foldlx' step begin done m = get $ go m begin
797foldlx' step begin done m = get $ go m begin
797 where
798 where
798 {-# NOINLINE get #-}
799 {-# NOINLINE get #-}
799− get :: Stream m x -> m b
800+ get :: StreamK m x -> m b
800 get m1 =
801 get m1 =
801 -- XXX we are not strictly evaluating the accumulator here. Is this
802 -- XXX we are not strictly evaluating the accumulator here. Is this
802 -- okay?
803 -- okay?
@@ -808,7 +809,7 @@ foldlx' step begin done m = get $ go m begin
808 -- however that is more expensive because of unnecessary recursion
809 -- however that is more expensive because of unnecessary recursion
809 -- that cannot be tail call optimized. Unfolding recursion explicitly via
810 -- that cannot be tail call optimized. Unfolding recursion explicitly via
810 -- continuations is much more efficient.
811 -- continuations is much more efficient.
811− go :: Stream m a -> x -> Stream m x
812+ go :: StreamK m a -> x -> StreamK m x
812 go m1 !acc = mkStream $ \_ yld sng _ ->
813 go m1 !acc = mkStream $ \_ yld sng _ ->
813 let stop = sng acc
814 let stop = sng acc
814 single a = sng $ step acc a
815 single a = sng $ step acc a
@@ -819,7 +820,7 @@ foldlx' step begin done m = get $ go m begin
819
820
820-- | Strict left associative fold.
821-- | Strict left associative fold.
821{-# INLINE foldl' #-}
822{-# INLINE foldl' #-}
822−foldl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> m b
823+foldl' :: Monad m => (b -> a -> b) -> b -> StreamK m a -> m b
823foldl' step begin = foldlx' step begin id
824foldl' step begin = foldlx' step begin id
824
825
825------------------------------------------------------------------------------
826------------------------------------------------------------------------------
@@ -836,7 +837,7 @@ foldl' step begin = foldlx' step begin id
836-- > drain = foldl' (\_ _ -> ()) ()
837-- > drain = foldl' (\_ _ -> ()) ()
837-- > drain = mapM_ (\_ -> return ())
838-- > drain = mapM_ (\_ -> return ())
838{-# INLINE drain #-}
839{-# INLINE drain #-}
839−drain :: Monad m => Stream m a -> m ()
840+drain :: Monad m => StreamK m a -> m ()
840drain = foldrM (\_ xs -> xs) (return ())
841drain = foldrM (\_ xs -> xs) (return ())
841{-
842{-
842drain = go
843drain = go
@@ -849,7 +850,7 @@ drain = go
849-}
850-}
850
851
851{-# INLINE null #-}
852{-# INLINE null #-}
852−null :: Monad m => Stream m a -> m Bool
853+null :: Monad m => StreamK m a -> m Bool
853-- null = foldrM (\_ _ -> return True) (return False)
854-- null = foldrM (\_ _ -> return True) (return False)
854null m =
855null m =
855 let stop = return True
856 let stop = return True
@@ -876,7 +877,7 @@ infixr 6 `append`
876-- 'concatMapWith' et. al.
877-- 'concatMapWith' et. al.
877--
878--
878{-# INLINE append #-}
879{-# INLINE append #-}
879−append :: Stream m a -> Stream m a -> Stream m a
880+append :: StreamK m a -> StreamK m a -> StreamK m a
880-- XXX This doubles the time of toNullAp benchmark, may not be fusing properly
881-- XXX This doubles the time of toNullAp benchmark, may not be fusing properly
881-- serial xs ys = augmentS (\c n -> foldrS c n xs) ys
882-- serial xs ys = augmentS (\c n -> foldrS c n xs) ys
882append m1 m2 = go m1
883append m1 m2 = go m1
@@ -889,17 +890,17 @@ append m1 m2 = go m1
889
890
890-- join/merge/append streams depending on consM
891-- join/merge/append streams depending on consM
891{-# INLINE conjoin #-}
892{-# INLINE conjoin #-}
892−conjoin :: Monad m => Stream m a -> Stream m a -> Stream m a
893+conjoin :: Monad m => StreamK m a -> StreamK m a -> StreamK m a
893conjoin xs = augmentSM (\c n -> foldrSM c n xs)
894conjoin xs = augmentSM (\c n -> foldrSM c n xs)
894
895
895−instance Semigroup (Stream m a) where
896+instance Semigroup (StreamK m a) where
896 (<>) = append
897 (<>) = append
897
898
898------------------------------------------------------------------------------
899------------------------------------------------------------------------------
899-- Monoid
900-- Monoid
900------------------------------------------------------------------------------
901------------------------------------------------------------------------------
901
902
902−instance Monoid (Stream m a) where
903+instance Monoid (StreamK m a) where
903 mempty = nil
904 mempty = nil
904 mappend = (<>)
905 mappend = (<>)
905
906
@@ -912,11 +913,11 @@ instance Monoid (Stream m a) where
912-- rewrite rules. Ideally don't run hlint on this file.
913-- rewrite rules. Ideally don't run hlint on this file.
913{-# INLINE_LATE mapFB #-}
914{-# INLINE_LATE mapFB #-}
914mapFB :: forall b m a.
915mapFB :: forall b m a.
915− (b -> Stream m b -> Stream m b)
916+ (b -> StreamK m b -> StreamK m b)
916 -> (a -> b)
917 -> (a -> b)
917 -> a
918 -> a
918− -> Stream m b
919+ -> StreamK m b
919− -> Stream m b
920+ -> StreamK m b
920mapFB c f = \x ys -> c (f x) ys
921mapFB c f = \x ys -> c (f x) ys
921
922
922{-# RULES
923{-# RULES
@@ -925,7 +926,7 @@ mapFB c f = \x ys -> c (f x) ys
925 #-}
926 #-}
926
927
927{-# INLINE map #-}
928{-# INLINE map #-}
928−map :: (a -> b) -> Stream m a -> Stream m b
929+map :: (a -> b) -> StreamK m a -> StreamK m b
929map f xs = buildS (\c n -> foldrS (mapFB c f) n xs)
930map f xs = buildS (\c n -> foldrS (mapFB c f) n xs)
930
931
931-- XXX This definition might potentially be more efficient, but the cost in the
932-- XXX This definition might potentially be more efficient, but the cost in the
@@ -964,15 +965,15 @@ mapMFB c f x = c (x >>= f)
964-- XXX fusion would be easier for monomoprhic stream types.
965-- XXX fusion would be easier for monomoprhic stream types.
965-- {-# RULES "mapM serial" mapM = mapMSerial #-}
966-- {-# RULES "mapM serial" mapM = mapMSerial #-}
966{-# INLINE mapMSerial #-}
967{-# INLINE mapMSerial #-}
967−mapMSerial :: Monad m => (a -> m b) -> Stream m a -> Stream m b
968+mapMSerial :: Monad m => (a -> m b) -> StreamK m a -> StreamK m b
968mapMSerial f xs = buildSM (\c n -> foldrSMShared (mapMFB c f) n xs)
969mapMSerial f xs = buildSM (\c n -> foldrSMShared (mapMFB c f) n xs)
969
970
970{-# INLINE mapMWith #-}
971{-# INLINE mapMWith #-}
971mapMWith ::
972mapMWith ::
972− (m b -> Stream m b -> Stream m b)
973+ (m b -> StreamK m b -> StreamK m b)
973 -> (a -> m b)
974 -> (a -> m b)
974− -> Stream m a
975+ -> StreamK m a
975− -> Stream m b
976+ -> StreamK m b
976mapMWith cns f = foldrSShared (\x xs -> f x `cns` xs) nil
977mapMWith cns f = foldrSShared (\x xs -> f x `cns` xs) nil
977
978
978{-
979{-
@@ -987,7 +988,7 @@ mapMWith cns f = go
987
988
988-- XXX in fact use the Stream type everywhere and only use polymorphism in the
989-- XXX in fact use the Stream type everywhere and only use polymorphism in the
989-- high level modules/prelude.
990-- high level modules/prelude.
990−instance Monad m => Functor (Stream m) where
991+instance Monad m => Functor (StreamK m) where
991 fmap = map
992 fmap = map
992
993
993------------------------------------------------------------------------------
994------------------------------------------------------------------------------
@@ -1003,8 +1004,8 @@ instance Monad m => Functor (Stream m) where
1003-- well, because they do not get inlined. Need to add INLINE in Ord class in
1004-- well, because they do not get inlined. Need to add INLINE in Ord class in
1004-- base?
1005-- base?
1005
1006
1006−instance IsList (Stream Identity a) where
1007+instance IsList (StreamK Identity a) where
1007− type (Item (Stream Identity a)) = a
1008+ type (Item (StreamK Identity a)) = a
1008
1009
1009 {-# INLINE fromList #-}
1010 {-# INLINE fromList #-}
1010 fromList = fromFoldable
1011 fromList = fromFoldable
@@ -1014,11 +1015,11 @@ instance IsList (Stream Identity a) where
1014
1015
1015-- XXX Fix these
1016-- XXX Fix these
1016{-
1017{-
1017−instance Eq a => Eq (Stream Identity a) where
1018+instance Eq a => Eq (StreamK Identity a) where
1018 {-# INLINE (==) #-}
1019 {-# INLINE (==) #-}
1019 (==) xs ys = runIdentity $ eqBy (==) xs ys
1020 (==) xs ys = runIdentity $ eqBy (==) xs ys
1020
1021
1021−instance Ord a => Ord (Stream Identity a) where
1022+instance Ord a => Ord (StreamK Identity a) where
1022 {-# INLINE compare #-}
1023 {-# INLINE compare #-}
1023 compare xs ys = runIdentity $ cmpBy compare xs ys
1024 compare xs ys = runIdentity $ cmpBy compare xs ys
1024
1025
@@ -1053,18 +1054,18 @@ instance Ord a => Ord (Stream Identity a) where
1053 min x y = if x <= y then x else y
1054 min x y = if x <= y then x else y
1054-}
1055-}
1055
1056
1056−instance Show a => Show (Stream Identity a) where
1057+instance Show a => Show (StreamK Identity a) where
1057 showsPrec p dl = showParen (p > 10) $
1058 showsPrec p dl = showParen (p > 10) $
1058 showString "fromList " . shows (toList dl)
1059 showString "fromList " . shows (toList dl)
1059
1060
1060−instance Read a => Read (Stream Identity a) where
1061+instance Read a => Read (StreamK Identity a) where
1061 readPrec = parens $ prec 10 $ do
1062 readPrec = parens $ prec 10 $ do
1062 Ident "fromList" <- lexP
1063 Ident "fromList" <- lexP
1063 fromList <$> readPrec
1064 fromList <$> readPrec
1064
1065
1065 readListPrec = readListPrecDefault
1066 readListPrec = readListPrecDefault
1066
1067
1067−instance (a ~ Char) => IsString (Stream Identity a) where
1068+instance (a ~ Char) => IsString (StreamK Identity a) where
1068 {-# INLINE fromString #-}
1069 {-# INLINE fromString #-}
1069 fromString = fromList
1070 fromString = fromList
1070
1071
@@ -1074,7 +1075,7 @@ instance (a ~ Char) => IsString (Stream Identity a) where
1074
1075
1075-- | Lazy right associative fold.
1076-- | Lazy right associative fold.
1076{-# INLINE foldr #-}
1077{-# INLINE foldr #-}
1077−foldr :: Monad m => (a -> b -> b) -> b -> Stream m a -> m b
1078+foldr :: Monad m => (a -> b -> b) -> b -> StreamK m a -> m b
1078foldr step acc = foldrM (\x xs -> xs >>= \b -> return (step x b)) (return acc)
1079foldr step acc = foldrM (\x xs -> xs >>= \b -> return (step x b)) (return acc)
1079
1080
1080-- The default Foldable instance has several issues:
1081-- The default Foldable instance has several issues:
@@ -1084,7 +1085,7 @@ foldr step acc = foldrM (\x xs -> xs >>= \b -> return (step x b)) (return acc)
1084-- use right folds, they cannot run in constant memory. We provide
1085-- use right folds, they cannot run in constant memory. We provide
1085-- implementations using strict left folds here.
1086-- implementations using strict left folds here.
1086
1087
1087−instance (Foldable m, Monad m) => Foldable (Stream m) where
1088+instance (Foldable m, Monad m) => Foldable (StreamK m) where
1088
1089
1089 {-# INLINE foldMap #-}
1090 {-# INLINE foldMap #-}
1090 foldMap f =
1091 foldMap f =
@@ -1136,7 +1137,7 @@ instance (Foldable m, Monad m) => Foldable (Stream m) where
1136-- Traversable
1137-- Traversable
1137-------------------------------------------------------------------------------
1138-------------------------------------------------------------------------------
1138
1139
1139−instance Traversable (Stream Identity) where
1140+instance Traversable (StreamK Identity) where
1140 {-# INLINE traverse #-}
1141 {-# INLINE traverse #-}
1141 traverse f xs =
1142 traverse f xs =
1142 runIdentity
1143 runIdentity
@@ -1153,17 +1154,17 @@ instance Traversable (Stream Identity) where
1153
1154
1154-- | Detach a stream from an SVar
1155-- | Detach a stream from an SVar
1155{-# INLINE unShare #-}
1156{-# INLINE unShare #-}
1156−unShare :: Stream m a -> Stream m a
1157+unShare :: StreamK m a -> StreamK m a
1157unShare x = mkStream $ \st yld sng stp ->
1158unShare x = mkStream $ \st yld sng stp ->
1158 foldStream st yld sng stp x
1159 foldStream st yld sng stp x
1159
1160
1160-- XXX the function stream and value stream can run in parallel
1161-- XXX the function stream and value stream can run in parallel
1161{-# INLINE crossApplyWith #-}
1162{-# INLINE crossApplyWith #-}
1162crossApplyWith ::
1163crossApplyWith ::
1163− (Stream m b -> Stream m b -> Stream m b)
1164+ (StreamK m b -> StreamK m b -> StreamK m b)
1164− -> Stream m (a -> b)
1165+ -> StreamK m (a -> b)
1165− -> Stream m a
1166+ -> StreamK m a
1166− -> Stream m b
1167+ -> StreamK m b
1167crossApplyWith par fstream stream = go1 fstream
1168crossApplyWith par fstream stream = go1 fstream
1168
1169
1169 where
1170 where
@@ -1192,9 +1193,9 @@ crossApplyWith par fstream stream = go1 fstream
1192--
1193--
1193{-# INLINE crossApply #-}
1194{-# INLINE crossApply #-}
1194crossApply ::
1195crossApply ::
1195− Stream m (a -> b)
1196+ StreamK m (a -> b)
1196− -> Stream m a
1197+ -> StreamK m a
1197− -> Stream m b
1198+ -> StreamK m b
1198crossApply fstream stream = go1 fstream
1199crossApply fstream stream = go1 fstream
1199
1200
1200 where
1201 where
@@ -1222,9 +1223,9 @@ crossApply fstream stream = go1 fstream
1222
1223
1223{-# INLINE crossApplySnd #-}
1224{-# INLINE crossApplySnd #-}
1224crossApplySnd ::
1225crossApplySnd ::
1225− Stream m a
1226+ StreamK m a
1226− -> Stream m b
1227+ -> StreamK m b
1227− -> Stream m b
1228+ -> StreamK m b
1228crossApplySnd fstream stream = go1 fstream
1229crossApplySnd fstream stream = go1 fstream
1229
1230
1230 where
1231 where
@@ -1246,9 +1247,9 @@ crossApplySnd fstream stream = go1 fstream
1246
1247
1247{-# INLINE crossApplyFst #-}
1248{-# INLINE crossApplyFst #-}
1248crossApplyFst ::
1249crossApplyFst ::
1249− Stream m a
1250+ StreamK m a
1250− -> Stream m b
1251+ -> StreamK m b
1251− -> Stream m a
1252+ -> StreamK m a
1252crossApplyFst fstream stream = go1 fstream
1253crossApplyFst fstream stream = go1 fstream
1253
1254
1254 where
1255 where
@@ -1282,10 +1283,10 @@ crossApplyFst fstream stream = go1 fstream
1282-- Note that the second stream is evaluated multiple times.
1283-- Note that the second stream is evaluated multiple times.
1283--
1284--
1284{-# INLINE crossWith #-}
1285{-# INLINE crossWith #-}
1285−crossWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
1286+crossWith :: Monad m => (a -> b -> c) -> StreamK m a -> StreamK m b -> StreamK m c
1286crossWith f m1 m2 = fmap f m1 `crossApply` m2
1287crossWith f m1 m2 = fmap f m1 `crossApply` m2
1287
1288
1288−-- | Given a @Stream m a@ and @Stream m b@ generate a stream with all possible
1289+-- | Given a @StreamK m a@ and @StreamK m b@ generate a stream with all possible
1289-- combinations of the tuple @(a, b)@.
1290-- combinations of the tuple @(a, b)@.
1290--
1291--
1291-- Definition:
1292-- Definition:
@@ -1304,7 +1305,7 @@ crossWith f m1 m2 = fmap f m1 `crossApply` m2
1304--
1305--
1305-- /Pre-release/
1306-- /Pre-release/
1306{-# INLINE cross #-}
1307{-# INLINE cross #-}
1307−cross :: Monad m => Stream m a -> Stream m b -> Stream m (a, b)
1308+cross :: Monad m => StreamK m a -> StreamK m b -> StreamK m (a, b)
1308cross = crossWith (,)
1309cross = crossWith (,)
1309
1310
1310-- XXX This is just concatMapWith with arguments flipped. We need to keep this
1311-- XXX This is just concatMapWith with arguments flipped. We need to keep this
@@ -1313,10 +1314,10 @@ cross = crossWith (,)
1313-- if the argument order is changed.
1314-- if the argument order is changed.
1314{-# INLINE bindWith #-}
1315{-# INLINE bindWith #-}
1315bindWith ::
1316bindWith ::
1316− (Stream m b -> Stream m b -> Stream m b)
1317+ (StreamK m b -> StreamK m b -> StreamK m b)
1317− -> Stream m a
1318+ -> StreamK m a
1318− -> (a -> Stream m b)
1319+ -> (a -> StreamK m b)
1319− -> Stream m b
1320+ -> StreamK m b
1320bindWith par m1 f = go m1
1321bindWith par m1 f = go m1
1321 where
1322 where
1322 go m =
1323 go m =
@@ -1341,14 +1342,14 @@ bindWith par m1 f = go m1
1341{-# INLINE concatMapWith #-}
1342{-# INLINE concatMapWith #-}
1342concatMapWith
1343concatMapWith
1343 ::
1344 ::
1344− (Stream m b -> Stream m b -> Stream m b)
1345+ (StreamK m b -> StreamK m b -> StreamK m b)
1345− -> (a -> Stream m b)
1346+ -> (a -> StreamK m b)
1346− -> Stream m a
1347+ -> StreamK m a
1347− -> Stream m b
1348+ -> StreamK m b
1348concatMapWith par f xs = bindWith par xs f
1349concatMapWith par f xs = bindWith par xs f
1349
1350
1350{-# INLINE concatMap #-}
1351{-# INLINE concatMap #-}
1351−concatMap :: (a -> Stream m b) -> Stream m a -> Stream m b
1352+concatMap :: (a -> StreamK m b) -> StreamK m a -> StreamK m b
1352concatMap = concatMapWith append
1353concatMap = concatMapWith append
1353
1354
1354{-
1355{-
@@ -1392,10 +1393,10 @@ concatMap_ f xs = buildS
1392{-# INLINE mergeMapWith #-}
1393{-# INLINE mergeMapWith #-}
1393mergeMapWith
1394mergeMapWith
1394 ::
1395 ::
1395− (Stream m b -> Stream m b -> Stream m b)
1396+ (StreamK m b -> StreamK m b -> StreamK m b)
1396− -> (a -> Stream m b)
1397+ -> (a -> StreamK m b)
1397− -> Stream m a
1398+ -> StreamK m a
1398− -> Stream m b
1399+ -> StreamK m b
1399mergeMapWith combine f str = go (leafPairs str)
1400mergeMapWith combine f str = go (leafPairs str)
1400
1401
1401 where
1402 where
@@ -1448,7 +1449,7 @@ mergeMapWith combine f str = go (leafPairs str)
1448 in foldStream (adaptState st) yieldk single stop stream
1449 in foldStream (adaptState st) yieldk single stop stream
1449
1450
1450{-
1451{-
1451−instance Monad m => Applicative (Stream m) where
1452+instance Monad m => Applicative (StreamK m) where
1452 {-# INLINE pure #-}
1453 {-# INLINE pure #-}
1453 pure = fromPure
1454 pure = fromPure
1454
1455
@@ -1467,7 +1468,7 @@ instance Monad m => Applicative (Stream m) where
1467-- NOTE: even though concatMap for StreamD is 3x faster compared to StreamK,
1468-- NOTE: even though concatMap for StreamD is 3x faster compared to StreamK,
1468-- the monad instance of StreamD is slower than StreamK after foldr/build
1469-- the monad instance of StreamD is slower than StreamK after foldr/build
1469-- fusion.
1470-- fusion.
1470−instance Monad m => Monad (Stream m) where
1471+instance Monad m => Monad (StreamK m) where
1471 {-# INLINE return #-}
1472 {-# INLINE return #-}
1472 return = pure
1473 return = pure
1473
1474
@@ -1506,10 +1507,10 @@ concatUnfoldr = undefined
1506--
1507--
1507{-# INLINE concatIterateWith #-}
1508{-# INLINE concatIterateWith #-}
1508concatIterateWith ::
1509concatIterateWith ::
1509− (Stream m a -> Stream m a -> Stream m a)
1510+ (StreamK m a -> StreamK m a -> StreamK m a)
1510− -> (a -> Stream m a)
1511+ -> (a -> StreamK m a)
1511− -> Stream m a
1512+ -> StreamK m a
1512− -> Stream m a
1513+ -> StreamK m a
1513concatIterateWith combine f = iterateStream
1514concatIterateWith combine f = iterateStream
1514
1515
1515 where
1516 where
@@ -1532,10 +1533,10 @@ concatIterateWith combine f = iterateStream
1532--
1533--
1533{-# INLINE mergeIterateWith #-}
1534{-# INLINE mergeIterateWith #-}
1534mergeIterateWith ::
1535mergeIterateWith ::
1535− (Stream m a -> Stream m a -> Stream m a)
1536+ (StreamK m a -> StreamK m a -> StreamK m a)
1536− -> (a -> Stream m a)
1537+ -> (a -> StreamK m a)
1537− -> Stream m a
1538+ -> StreamK m a
1538− -> Stream m a
1539+ -> StreamK m a
1539mergeIterateWith combine f = iterateStream
1540mergeIterateWith combine f = iterateStream
1540
1541
1541 where
1542 where
@@ -1566,11 +1567,11 @@ mergeIterateWith combine f = iterateStream
1566{-# INLINE concatIterateScanWith #-}
1567{-# INLINE concatIterateScanWith #-}
1567concatIterateScanWith
1568concatIterateScanWith
1568 :: Monad m
1569 :: Monad m
1569− => (Stream m a -> Stream m a -> Stream m a)
1570+ => (StreamK m a -> StreamK m a -> StreamK m a)
1570− -> (b -> a -> m (b, Stream m a))
1571+ -> (b -> a -> m (b, StreamK m a))
1571 -> m b
1572 -> m b
1572− -> Stream m a
1573+ -> StreamK m a
1573− -> Stream m a
1574+ -> StreamK m a
1574concatIterateScanWith combine f initial stream =
1575concatIterateScanWith combine f initial stream =
1575 concatEffect $ do
1576 concatEffect $ do
1576 b <- initial
1577 b <- initial
@@ -1598,9 +1599,9 @@ concatIterateScanWith combine f initial stream =
1598{-
1599{-
1599concatMapEitherWith
1600concatMapEitherWith
1600 :: (forall x. t m x -> t m x -> t m x)
1601 :: (forall x. t m x -> t m x -> t m x)
1601− -> (a -> t m (Either (Stream m b) b))
1602+ -> (a -> t m (Either (StreamK m b) b))
1602− -> Stream m a
1603+ -> StreamK m a
1603− -> Stream m b
1604+ -> StreamK m b
1604concatMapEitherWith = undefined
1605concatMapEitherWith = undefined
1605-}
1606-}
1606
1607
@@ -1622,10 +1623,10 @@ concatMapEitherWith = undefined
1622{-# INLINE concatIterateLeftsWith #-}
1623{-# INLINE concatIterateLeftsWith #-}
1623concatIterateLeftsWith
1624concatIterateLeftsWith
1624 :: (b ~ Either a c)
1625 :: (b ~ Either a c)
1625− => (Stream m b -> Stream m b -> Stream m b)
1626+ => (StreamK m b -> StreamK m b -> StreamK m b)
1626− -> (a -> Stream m b)
1627+ -> (a -> StreamK m b)
1627− -> Stream m b
1628+ -> StreamK m b
1628− -> Stream m b
1629+ -> StreamK m b
1629concatIterateLeftsWith combine f =
1630concatIterateLeftsWith combine f =
1630 concatIterateWith combine (either f (const nil))
1631 concatIterateWith combine (either f (const nil))
1631
1632
@@ -1650,7 +1651,7 @@ infixr 6 `interleave`
1650-- streams.
1651-- streams.
1651--
1652--
1652{-# INLINE interleave #-}
1653{-# INLINE interleave #-}
1653−interleave :: Stream m a -> Stream m a -> Stream m a
1654+interleave :: StreamK m a -> StreamK m a -> StreamK m a
1654interleave m1 m2 = mkStream $ \st yld sng stp -> do
1655interleave m1 m2 = mkStream $ \st yld sng stp -> do
1655 let stop = foldStream st yld sng stp m2
1656 let stop = foldStream st yld sng stp m2
1656 single a = yld a m2
1657 single a = yld a m2
@@ -1662,7 +1663,7 @@ infixr 6 `interleaveFst`
1662-- | Like `interleave` but stops interleaving as soon as the first stream stops.
1663-- | Like `interleave` but stops interleaving as soon as the first stream stops.
1663--
1664--
1664{-# INLINE interleaveFst #-}
1665{-# INLINE interleaveFst #-}
1665−interleaveFst :: Stream m a -> Stream m a -> Stream m a
1666+interleaveFst :: StreamK m a -> StreamK m a -> StreamK m a
1666interleaveFst m1 m2 = mkStream $ \st yld sng stp -> do
1667interleaveFst m1 m2 = mkStream $ \st yld sng stp -> do
1667 let yieldFirst a r = yld a (yieldSecond r m2)
1668 let yieldFirst a r = yld a (yieldSecond r m2)
1668 in foldStream st yieldFirst sng stp m1
1669 in foldStream st yieldFirst sng stp m1
@@ -1681,7 +1682,7 @@ infixr 6 `interleaveMin`
1681-- stops.
1682-- stops.
1682--
1683--
1683{-# INLINE interleaveMin #-}
1684{-# INLINE interleaveMin #-}
1684−interleaveMin :: Stream m a -> Stream m a -> Stream m a
1685+interleaveMin :: StreamK m a -> StreamK m a -> StreamK m a
1685interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
1686interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
1686 let stop = stp
1687 let stop = stp
1687 -- "single a" is defined as "yld a (interleaveMin m2 nil)" instead of
1688 -- "single a" is defined as "yld a (interleaveMin m2 nil)" instead of
@@ -1696,7 +1697,7 @@ interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
1696-------------------------------------------------------------------------------
1697-------------------------------------------------------------------------------
1697
1698
1698{-# INLINE unfoldr #-}
1699{-# INLINE unfoldr #-}
1699−unfoldr :: (b -> Maybe (a, b)) -> b -> Stream m a
1700+unfoldr :: (b -> Maybe (a, b)) -> b -> StreamK m a
1700unfoldr next s0 = build $ \yld stp ->
1701unfoldr next s0 = build $ \yld stp ->
1701 let go s =
1702 let go s =
1702 case next s of
1703 case next s of
@@ -1706,10 +1707,10 @@ unfoldr next s0 = build $ \yld stp ->
1706
1707
1707{-# INLINE unfoldrMWith #-}
1708{-# INLINE unfoldrMWith #-}
1708unfoldrMWith :: Monad m =>
1709unfoldrMWith :: Monad m =>
1709− (m a -> Stream m a -> Stream m a)
1710+ (m a -> StreamK m a -> StreamK m a)
1710 -> (b -> m (Maybe (a, b)))
1711 -> (b -> m (Maybe (a, b)))
1711 -> b
1712 -> b
1712− -> Stream m a
1713+ -> StreamK m a
1713unfoldrMWith cns step = go
1714unfoldrMWith cns step = go
1714
1715
1715 where
1716 where
@@ -1721,14 +1722,14 @@ unfoldrMWith cns step = go
1721 Nothing -> stp
1722 Nothing -> stp
1722
1723
1723{-# INLINE unfoldrM #-}
1724{-# INLINE unfoldrM #-}
1724−unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> Stream m a
1725+unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> StreamK m a
1725unfoldrM = unfoldrMWith consM
1726unfoldrM = unfoldrMWith consM
1726
1727
1727-- | Generate an infinite stream by repeating a pure value.
1728-- | Generate an infinite stream by repeating a pure value.
1728--
1729--
1729-- /Pre-release/
1730-- /Pre-release/
1730{-# INLINE repeat #-}
1731{-# INLINE repeat #-}
1731−repeat :: a -> Stream m a
1732+repeat :: a -> StreamK m a
1732repeat a = let x = cons a x in x
1733repeat a = let x = cons a x in x
1733
1734
1734-- | Like 'repeatM' but takes a stream 'cons' operation to combine the actions
1735-- | Like 'repeatM' but takes a stream 'cons' operation to combine the actions
@@ -1744,7 +1745,7 @@ repeatMWith cns = go
1744 go m = m `cns` go m
1745 go m = m `cns` go m
1745
1746
1746{-# INLINE replicateMWith #-}
1747{-# INLINE replicateMWith #-}
1747−replicateMWith :: (m a -> Stream m a -> Stream m a) -> Int -> m a -> Stream m a
1748+replicateMWith :: (m a -> StreamK m a -> StreamK m a) -> Int -> m a -> StreamK m a
1748replicateMWith cns n m = go n
1749replicateMWith cns n m = go n
1749
1750
1750 where
1751 where
@@ -1753,7 +1754,7 @@ replicateMWith cns n m = go n
1753
1754
1754{-# INLINE fromIndicesMWith #-}
1755{-# INLINE fromIndicesMWith #-}
1755fromIndicesMWith ::
1756fromIndicesMWith ::
1756− (m a -> Stream m a -> Stream m a) -> (Int -> m a) -> Stream m a
1757+ (m a -> StreamK m a -> StreamK m a) -> (Int -> m a) -> StreamK m a
1757fromIndicesMWith cns gen = go 0
1758fromIndicesMWith cns gen = go 0
1758
1759
1759 where
1760 where
@@ -1763,7 +1764,7 @@ fromIndicesMWith cns gen = go 0
1763
1764
1764{-# INLINE iterateMWith #-}
1765{-# INLINE iterateMWith #-}
1765iterateMWith :: Monad m =>
1766iterateMWith :: Monad m =>
1766− (m a -> Stream m a -> Stream m a) -> (a -> m a) -> m a -> Stream m a
1767+ (m a -> StreamK m a -> StreamK m a) -> (a -> m a) -> m a -> StreamK m a
1767iterateMWith cns step = go
1768iterateMWith cns step = go
1768
1769
1769 where
1770 where
@@ -1773,11 +1774,11 @@ iterateMWith cns step = go
1773 foldStreamShared st stp sng yld (return next `cns` go (step next))
1774 foldStreamShared st stp sng yld (return next `cns` go (step next))
1774
1775
1775{-# INLINE headPartial #-}
1776{-# INLINE headPartial #-}
1776−headPartial :: Monad m => Stream m a -> m a
1777+headPartial :: Monad m => StreamK m a -> m a
1777headPartial = foldrM (\x _ -> return x) (error "head of nil")
1778headPartial = foldrM (\x _ -> return x) (error "head of nil")
1778
1779
1779{-# INLINE tailPartial #-}
1780{-# INLINE tailPartial #-}
1780−tailPartial :: Stream m a -> Stream m a
1781+tailPartial :: StreamK m a -> StreamK m a
1781tailPartial m = mkStream $ \st yld sng stp ->
1782tailPartial m = mkStream $ \st yld sng stp ->
1782 let stop = error "tail of nil"
1783 let stop = error "tail of nil"
1783 single _ = stp
1784 single _ = stp
@@ -1835,7 +1836,7 @@ tailPartial m = mkStream $ \st yld sng stp ->
1835--
1836--
1836-- /Pre-release/
1837-- /Pre-release/
1837{-# INLINE mfix #-}
1838{-# INLINE mfix #-}
1838−mfix :: Monad m => (m a -> Stream m a) -> Stream m a
1839+mfix :: Monad m => (m a -> StreamK m a) -> StreamK m a
1839mfix f = mkStream $ \st yld sng stp ->
1840mfix f = mkStream $ \st yld sng stp ->
1840 let single a = foldStream st yld sng stp $ a `cons` ys
1841 let single a = foldStream st yld sng stp $ a `cons` ys
1841 yieldk a _ = foldStream st yld sng stp $ a `cons` ys
1842 yieldk a _ = foldStream st yld sng stp $ a `cons` ys
@@ -1862,11 +1863,11 @@ mfix f = mkStream $ \st yld sng stp ->
1862--
1863--
1863-- @since 0.2.0
1864-- @since 0.2.0
1864{-# INLINE fromFoldable #-}
1865{-# INLINE fromFoldable #-}
1865−fromFoldable :: Foldable f => f a -> Stream m a
1866+fromFoldable :: Foldable f => f a -> StreamK m a
1866fromFoldable = Prelude.foldr cons nil
1867fromFoldable = Prelude.foldr cons nil
1867
1868
1868{-# INLINE fromFoldableM #-}
1869{-# INLINE fromFoldableM #-}
1869−fromFoldableM :: (Foldable f, Monad m) => f (m a) -> Stream m a
1870+fromFoldableM :: (Foldable f, Monad m) => f (m a) -> StreamK m a
1870fromFoldableM = Prelude.foldr consM nil
1871fromFoldableM = Prelude.foldr consM nil
1871
1872
1872-------------------------------------------------------------------------------
1873-------------------------------------------------------------------------------
@@ -1874,7 +1875,7 @@ fromFoldableM = Prelude.foldr consM nil
1874-------------------------------------------------------------------------------
1875-------------------------------------------------------------------------------
1875
1876
1876{-# INLINE uncons #-}
1877{-# INLINE uncons #-}
1877−uncons :: Applicative m => Stream m a -> m (Maybe (a, Stream m a))
1878+uncons :: Applicative m => StreamK m a -> m (Maybe (a, StreamK m a))
1878uncons m =
1879uncons m =
1879 let stop = pure Nothing
1880 let stop = pure Nothing
1880 single a = pure (Just (a, nil))
1881 single a = pure (Just (a, nil))
@@ -1882,7 +1883,7 @@ uncons m =
1882 in foldStream defState yieldk single stop m
1883 in foldStream defState yieldk single stop m
1883
1884
1884{-# INLINE tail #-}
1885{-# INLINE tail #-}
1885−tail :: Applicative m => Stream m a -> m (Maybe (Stream m a))
1886+tail :: Applicative m => StreamK m a -> m (Maybe (StreamK m a))
1886tail =
1887tail =
1887 let stop = pure Nothing
1888 let stop = pure Nothing
1888 single _ = pure $ Just nil
1889 single _ = pure $ Just nil
@@ -1895,7 +1896,7 @@ tail =
1895--
1896--
1896-- /Pre-release/
1897-- /Pre-release/
1897{-# INLINE init #-}
1898{-# INLINE init #-}
1898−init :: Applicative m => Stream m a -> m (Maybe (Stream m a))
1899+init :: Applicative m => StreamK m a -> m (Maybe (StreamK m a))
1899init = go1
1900init = go1
1900 where
1901 where
1901 go1 m1 = do
1902 go1 m1 = do
@@ -1914,7 +1915,7 @@ init = go1
1914-- | Lazy left fold to a stream.
1915-- | Lazy left fold to a stream.
1915{-# INLINE foldlS #-}
1916{-# INLINE foldlS #-}
1916foldlS ::
1917foldlS ::
1917− (Stream m b -> a -> Stream m b) -> Stream m b -> Stream m a -> Stream m b
1918+ (StreamK m b -> a -> StreamK m b) -> StreamK m b -> StreamK m a -> StreamK m b
1918foldlS step = go
1919foldlS step = go
1919 where
1920 where
1920 go acc rest = mkStream $ \st yld sng stp ->
1921 go acc rest = mkStream $ \st yld sng stp ->
@@ -1925,7 +1926,7 @@ foldlS step = go
1925 in foldStream (adaptState st) yieldk single stop rest
1926 in foldStream (adaptState st) yieldk single stop rest
1926
1927
1927{-# INLINE reverse #-}
1928{-# INLINE reverse #-}
1928−reverse :: Stream m a -> Stream m a
1929+reverse :: StreamK m a -> StreamK m a
1929reverse = foldlS (flip cons) nil
1930reverse = foldlS (flip cons) nil
1930
1931
1931------------------------------------------------------------------------------
1932------------------------------------------------------------------------------
@@ -1934,20 +1935,20 @@ reverse = foldlS (flip cons) nil
1934
1935
1935-- | Run an action before evaluating the stream.
1936-- | Run an action before evaluating the stream.
1936{-# INLINE before #-}
1937{-# INLINE before #-}
1937−before :: Monad m => m b -> Stream m a -> Stream m a
1938+before :: Monad m => m b -> StreamK m a -> StreamK m a
1938before action stream =
1939before action stream =
1939 mkStream $ \st yld sng stp ->
1940 mkStream $ \st yld sng stp ->
1940 action >> foldStreamShared st yld sng stp stream
1941 action >> foldStreamShared st yld sng stp stream
1941
1942
1942-- | concat . fromEffect
1943-- | concat . fromEffect
1943{-# INLINE concatEffect #-}
1944{-# INLINE concatEffect #-}
1944−concatEffect :: Monad m => m (Stream m a) -> Stream m a
1945+concatEffect :: Monad m => m (StreamK m a) -> StreamK m a
1945concatEffect action =
1946concatEffect action =
1946 mkStream $ \st yld sng stp ->
1947 mkStream $ \st yld sng stp ->
1947 action >>= foldStreamShared st yld sng stp
1948 action >>= foldStreamShared st yld sng stp
1948
1949
1949{-# INLINE concatMapEffect #-}
1950{-# INLINE concatMapEffect #-}
1950−concatMapEffect :: Monad m => (b -> Stream m a) -> m b -> Stream m a
1951+concatMapEffect :: Monad m => (b -> StreamK m a) -> m b -> StreamK m a
1951concatMapEffect f action =
1952concatMapEffect f action =
1952 mkStream $ \st yld sng stp ->
1953 mkStream $ \st yld sng stp ->
1953 action >>= foldStreamShared st yld sng stp . f
1954 action >>= foldStreamShared st yld sng stp . f
@@ -1980,7 +1981,7 @@ concatMapEffect f action =
1980-- :}
1981-- :}
1981-- [(1,3),(1,4),(2,3),(2,4)]
1982-- [(1,3),(1,4),(2,3),(2,4)]
1982--
1983--
1983−newtype CrossStreamK m a = CrossStreamK {unCrossStreamK :: Stream m a}
1984+newtype CrossStreamK m a = CrossStreamK {unCrossStreamK :: StreamK m a}
1984 deriving (Functor, Semigroup, Monoid, Foldable)
1985 deriving (Functor, Semigroup, Monoid, Foldable)
1985
1986
1986-- | Wrap the 'StreamK' type in a 'CrossStreamK' newtype to enable cross
1987-- | Wrap the 'StreamK' type in a 'CrossStreamK' newtype to enable cross
core/src/Streamly/Internal/Data/Stream/Type.hs+3−3
@@ -79,7 +79,7 @@ import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
79--
79--
80-- >>> (<>) = Stream.append
80-- >>> (<>) = Stream.append
81--
81--
82−newtype StreamK m a = StreamK (K.Stream m a)
82+newtype StreamK m a = StreamK (K.StreamK m a)
83 -- XXX when deriving do we inherit an INLINE?
83 -- XXX when deriving do we inherit an INLINE?
84 deriving (Semigroup, Monoid)
84 deriving (Semigroup, Monoid)
85
85
@@ -90,11 +90,11 @@ type Stream = StreamK
90------------------------------------------------------------------------------
90------------------------------------------------------------------------------
91
91
92{-# INLINE_EARLY fromStreamK #-}
92{-# INLINE_EARLY fromStreamK #-}
93−fromStreamK :: K.Stream m a -> Stream m a
93+fromStreamK :: K.StreamK m a -> Stream m a
94fromStreamK = StreamK
94fromStreamK = StreamK
95
95
96{-# INLINE_EARLY toStreamK #-}
96{-# INLINE_EARLY toStreamK #-}
97−toStreamK :: Stream m a -> K.Stream m a
97+toStreamK :: Stream m a -> K.StreamK m a
98toStreamK (StreamK k) = k
98toStreamK (StreamK k) = k
99
99
100{-# INLINE_EARLY fromStreamD #-}
100{-# INLINE_EARLY fromStreamD #-}
core/src/Streamly/Internal/Data/Unfold.hs+1−1
@@ -591,7 +591,7 @@ fromStreamD = Unfold step pure
591 Stop -> Stop) <$> step1 defState state1
591 Stop -> Stop) <$> step1 defState state1
592
592
593{-# INLINE_NORMAL fromStreamK #-}
593{-# INLINE_NORMAL fromStreamK #-}
594−fromStreamK :: Applicative m => Unfold m (K.Stream m a) a
594+fromStreamK :: Applicative m => Unfold m (K.StreamK m a) a
595fromStreamK = Unfold step pure
595fromStreamK = Unfold step pure
596
596
597 where
597 where
core/src/inline.hs+1−1
@@ -16,7 +16,7 @@
16-- Then, fromStreamK/toStreamK are inlined in the last phase:
16-- Then, fromStreamK/toStreamK are inlined in the last phase:
17--
17--
18-- {-# INLINE_LATE toStreamK #-}
18-- {-# INLINE_LATE toStreamK #-}
19−-- toStreamK :: Monad m => Stream m a -> K.Stream m a```
19+-- toStreamK :: Monad m => Stream m a -> K.StreamK m a```
20--
20--
21-- The fallback rules make sure that if we could not fuse the direct style
21-- The fallback rules make sure that if we could not fuse the direct style
22-- operations then better use the CPS style operation, because unfused direct
22-- operations then better use the CPS style operation, because unfused direct
src/Streamly/Internal/Data/Stream/Channel/Types.hs+4−4
@@ -815,10 +815,10 @@ cleanupSVar workerSet = do
815-- Used for concurrent evaluation of streams using a Channel.
815-- Used for concurrent evaluation of streams using a Channel.
816{-# INLINE concatMapDivK #-}
816{-# INLINE concatMapDivK #-}
817concatMapDivK :: Monad m =>
817concatMapDivK :: Monad m =>
818− (K.Stream m a -> m ())
818+ (K.StreamK m a -> m ())
819− -> (a -> K.Stream m b)
819+ -> (a -> K.StreamK m b)
820− -> K.Stream m a
820+ -> K.StreamK m a
821− -> K.Stream m b
821+ -> K.StreamK m b
822concatMapDivK useTail useHead stream =
822concatMapDivK useTail useHead stream =
823 K.mkStream $ \st yld sng stp -> do
823 K.mkStream $ \st yld sng stp -> do
824 let foldShared = K.foldStreamShared st yld sng stp
824 let foldShared = K.foldStreamShared st yld sng stp
src/Streamly/Internal/Data/Stream/Concurrent.hs+14−14
@@ -189,9 +189,9 @@ parEval modifier input = withChannel modifier input (const id)
189_appendGeneric :: MonadAsync m =>
189_appendGeneric :: MonadAsync m =>
190 ((Config -> Config) -> m (Channel m a))
190 ((Config -> Config) -> m (Channel m a))
191 -> (Config -> Config)
191 -> (Config -> Config)
192− -> K.Stream m a
192+ -> K.StreamK m a
193− -> K.Stream m a
193+ -> K.StreamK m a
194− -> K.Stream m a
194+ -> K.StreamK m a
195_appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
195_appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
196
196
197 where
197 where
@@ -216,7 +216,7 @@ _appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
216-- The output stream is the result of the evaluation.
216-- The output stream is the result of the evaluation.
217{-# INLINE appendWithK #-}
217{-# INLINE appendWithK #-}
218appendWithK :: MonadAsync m =>
218appendWithK :: MonadAsync m =>
219− (Config -> Config) -> K.Stream m a -> K.Stream m a -> K.Stream m a
219+ (Config -> Config) -> K.StreamK m a -> K.StreamK m a -> K.StreamK m a
220appendWithK modifier stream1 stream2 =
220appendWithK modifier stream1 stream2 =
221{-
221{-
222 if getOrdered (modifier defaultConfig)
222 if getOrdered (modifier defaultConfig)
@@ -236,7 +236,7 @@ appendWithK modifier stream1 stream2 =
236--
236--
237{-# INLINE _appendWithChanK #-}
237{-# INLINE _appendWithChanK #-}
238_appendWithChanK :: MonadAsync m =>
238_appendWithChanK :: MonadAsync m =>
239− Channel m a -> K.Stream m a -> K.Stream m a -> K.Stream m a
239+ Channel m a -> K.StreamK m a -> K.StreamK m a -> K.StreamK m a
240_appendWithChanK chan stream1 stream2 =
240_appendWithChanK chan stream1 stream2 =
241 K.before (toChannelK chan stream2) stream1
241 K.before (toChannelK chan stream2) stream1
242
242
@@ -284,8 +284,8 @@ parTwo modifier stream1 stream2 =
284{-# INLINE mkEnqueue #-}
284{-# INLINE mkEnqueue #-}
285mkEnqueue :: MonadAsync m =>
285mkEnqueue :: MonadAsync m =>
286 Channel m b
286 Channel m b
287− -> ((K.Stream m a -> m ()) -> K.Stream m a -> K.Stream m b)
287+ -> ((K.StreamK m a -> m ()) -> K.StreamK m a -> K.StreamK m b)
288− -> m (K.Stream m a -> m ())
288+ -> m (K.StreamK m a -> m ())
289mkEnqueue chan runner = do
289mkEnqueue chan runner = do
290 runInIO <- askRunInIO
290 runInIO <- askRunInIO
291 return
291 return
@@ -308,7 +308,7 @@ mkEnqueue chan runner = do
308-- concurrently map and evaluate a stream.
308-- concurrently map and evaluate a stream.
309{-# INLINE parConcatMapChanK #-}
309{-# INLINE parConcatMapChanK #-}
310parConcatMapChanK :: MonadAsync m =>
310parConcatMapChanK :: MonadAsync m =>
311− Channel m b -> (a -> K.Stream m b) -> K.Stream m a -> K.Stream m b
311+ Channel m b -> (a -> K.StreamK m b) -> K.StreamK m a -> K.StreamK m b
312parConcatMapChanK chan f stream =
312parConcatMapChanK chan f stream =
313 let run q = concatMapDivK q f
313 let run q = concatMapDivK q f
314 in K.concatMapEffect (`run` stream) (mkEnqueue chan run)
314 in K.concatMapEffect (`run` stream) (mkEnqueue chan run)
@@ -316,7 +316,7 @@ parConcatMapChanK chan f stream =
316
316
317{-# INLINE parConcatMapChanKAny #-}
317{-# INLINE parConcatMapChanKAny #-}
318parConcatMapChanKAny :: MonadAsync m =>
318parConcatMapChanKAny :: MonadAsync m =>
319− Channel m b -> (a -> K.Stream m b) -> K.Stream m a -> K.Stream m b
319+ Channel m b -> (a -> K.StreamK m b) -> K.StreamK m a -> K.StreamK m b
320parConcatMapChanKAny chan f stream =
320parConcatMapChanKAny chan f stream =
321 let done = K.nilM (stopChannel chan)
321 let done = K.nilM (stopChannel chan)
322 run q = concatMapDivK q (\x -> K.append (f x) done)
322 run q = concatMapDivK q (\x -> K.append (f x) done)
@@ -324,7 +324,7 @@ parConcatMapChanKAny chan f stream =
324
324
325{-# INLINE parConcatMapChanKFirst #-}
325{-# INLINE parConcatMapChanKFirst #-}
326parConcatMapChanKFirst :: MonadAsync m =>
326parConcatMapChanKFirst :: MonadAsync m =>
327− Channel m b -> (a -> K.Stream m b) -> K.Stream m a -> K.Stream m b
327+ Channel m b -> (a -> K.StreamK m b) -> K.StreamK m a -> K.StreamK m b
328parConcatMapChanKFirst chan f stream =
328parConcatMapChanKFirst chan f stream =
329 let done = K.nilM (stopChannel chan)
329 let done = K.nilM (stopChannel chan)
330 run q = concatMapDivK q f
330 run q = concatMapDivK q f
@@ -341,9 +341,9 @@ parConcatMapChanKFirst chan f stream =
341parConcatMapChanKGeneric :: MonadAsync m =>
341parConcatMapChanKGeneric :: MonadAsync m =>
342 (Config -> Config)
342 (Config -> Config)
343 -> Channel m b
343 -> Channel m b
344− -> (a -> K.Stream m b)
344+ -> (a -> K.StreamK m b)
345− -> K.Stream m a
345+ -> K.StreamK m a
346− -> K.Stream m b
346+ -> K.StreamK m b
347parConcatMapChanKGeneric modifier chan f stream = do
347parConcatMapChanKGeneric modifier chan f stream = do
348 let cfg = modifier defaultConfig
348 let cfg = modifier defaultConfig
349 case getStopWhen cfg of
349 case getStopWhen cfg of
@@ -359,7 +359,7 @@ parConcatMapChanKGeneric modifier chan f stream = do
359--
359--
360{-# INLINE parConcatMapK #-}
360{-# INLINE parConcatMapK #-}
361parConcatMapK :: MonadAsync m =>
361parConcatMapK :: MonadAsync m =>
362− (Config -> Config) -> (a -> K.Stream m b) -> K.Stream m a -> K.Stream m b
362+ (Config -> Config) -> (a -> K.StreamK m b) -> K.StreamK m a -> K.StreamK m b
363parConcatMapK modifier f input =
363parConcatMapK modifier f input =
364 let g = parConcatMapChanKGeneric modifier
364 let g = parConcatMapChanKGeneric modifier
365 in withChannelK modifier input (`g` f)
365 in withChannelK modifier input (`g` f)
src/Streamly/Internal/Data/Stream/Concurrent/Channel.hs+3−3
@@ -81,9 +81,9 @@ newChannel modifier =
81{-# INLINE withChannelK #-}
81{-# INLINE withChannelK #-}
82withChannelK :: MonadAsync m =>
82withChannelK :: MonadAsync m =>
83 (Config -> Config)
83 (Config -> Config)
84− -> K.Stream m a
84+ -> K.StreamK m a
85− -> (Channel m b -> K.Stream m a -> K.Stream m b)
85+ -> (Channel m b -> K.StreamK m a -> K.StreamK m b)
86− -> K.Stream m b
86+ -> K.StreamK m b
87withChannelK modifier input evaluator = K.concatEffect action
87withChannelK modifier input evaluator = K.concatEffect action
88
88
89 where
89 where
src/Streamly/Internal/Data/Stream/Concurrent/Channel/Append.hs+26−26
@@ -55,9 +55,9 @@ import Streamly.Internal.Data.Stream.Channel.Worker
55{-# INLINE enqueueLIFO #-}
55{-# INLINE enqueueLIFO #-}
56enqueueLIFO ::
56enqueueLIFO ::
57 Channel m a
57 Channel m a
58− -> IORef ([(RunInIO m, K.Stream m a)], [(RunInIO m, K.Stream m a)])
58+ -> IORef ([(RunInIO m, K.StreamK m a)], [(RunInIO m, K.StreamK m a)])
59 -> Bool
59 -> Bool
60− -> (RunInIO m, K.Stream m a)
60+ -> (RunInIO m, K.StreamK m a)
61 -> IO ()
61 -> IO ()
62enqueueLIFO sv q inner m = do
62enqueueLIFO sv q inner m = do
63 atomicModifyIORefCAS_ q $ \(xs, ys) ->
63 atomicModifyIORefCAS_ q $ \(xs, ys) ->
@@ -68,8 +68,8 @@ data QResult a = QEmpty | QOuter a | QInner a
68
68
69{-# INLINE dequeue #-}
69{-# INLINE dequeue #-}
70dequeue :: MonadIO m =>
70dequeue :: MonadIO m =>
71− IORef ([(RunInIO m, K.Stream m a)], [(RunInIO m, K.Stream m a)])
71+ IORef ([(RunInIO m, K.StreamK m a)], [(RunInIO m, K.StreamK m a)])
72− -> m (QResult (RunInIO m, K.Stream m a))
72+ -> m (QResult (RunInIO m, K.StreamK m a))
73dequeue qref =
73dequeue qref =
74 liftIO
74 liftIO
75 $ atomicModifyIORefCAS qref
75 $ atomicModifyIORefCAS qref
@@ -83,7 +83,7 @@ data WorkerStatus = Continue | Suspend
83{-# INLINE workLoopLIFO #-}
83{-# INLINE workLoopLIFO #-}
84workLoopLIFO
84workLoopLIFO
85 :: MonadRunInIO m
85 :: MonadRunInIO m
86− => IORef ([(RunInIO m, K.Stream m a)], [(RunInIO m, K.Stream m a)])
86+ => IORef ([(RunInIO m, K.StreamK m a)], [(RunInIO m, K.StreamK m a)])
87 -> Channel m a
87 -> Channel m a
88 -> Maybe WorkerInfo
88 -> Maybe WorkerInfo
89 -> m ()
89 -> m ()
@@ -144,7 +144,7 @@ workLoopLIFO qref sv winfo = run
144{-# INLINE workLoopLIFOLimited #-}
144{-# INLINE workLoopLIFOLimited #-}
145workLoopLIFOLimited
145workLoopLIFOLimited
146 :: forall m a. MonadRunInIO m
146 :: forall m a. MonadRunInIO m
147− => IORef ([(RunInIO m, K.Stream m a)], [(RunInIO m, K.Stream m a)])
147+ => IORef ([(RunInIO m, K.StreamK m a)], [(RunInIO m, K.StreamK m a)])
148 -> Channel m a
148 -> Channel m a
149 -> Maybe WorkerInfo
149 -> Maybe WorkerInfo
150 -> m ()
150 -> m ()
@@ -234,8 +234,8 @@ workLoopLIFOLimited qref sv winfo = run
234{-# INLINE enqueueAhead #-}
234{-# INLINE enqueueAhead #-}
235enqueueAhead ::
235enqueueAhead ::
236 Channel m a
236 Channel m a
237− -> IORef ([K.Stream m a], Int)
237+ -> IORef ([K.StreamK m a], Int)
238− -> (RunInIO m, K.Stream m a)
238+ -> (RunInIO m, K.StreamK m a)
239 -> IO ()
239 -> IO ()
240enqueueAhead sv q m = do
240enqueueAhead sv q m = do
241 -- XXX The queue is LIFO. When parConcatIterate queues more than one items
241 -- XXX The queue is LIFO. When parConcatIterate queues more than one items
@@ -444,7 +444,7 @@ updateHeapSeq hpVar seqNo =
444{-# INLINE underMaxHeap #-}
444{-# INLINE underMaxHeap #-}
445underMaxHeap ::
445underMaxHeap ::
446 Channel m a
446 Channel m a
447− -> Heap (Entry Int (AheadHeapEntry K.Stream m a))
447+ -> Heap (Entry Int (AheadHeapEntry K.StreamK m a))
448 -> IO Bool
448 -> IO Bool
449underMaxHeap sv hp = do
449underMaxHeap sv hp = do
450 (_, len) <- readIORef (outputQueue sv)
450 (_, len) <- readIORef (outputQueue sv)
@@ -466,7 +466,7 @@ underMaxHeap sv hp = do
466-- False => continue
466-- False => continue
467preStopCheck ::
467preStopCheck ::
468 Channel m a
468 Channel m a
469− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)) , Maybe Int)
469+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)) , Maybe Int)
470 -> IO Bool
470 -> IO Bool
471preStopCheck sv heap =
471preStopCheck sv heap =
472 -- check the stop condition under a lock before actually
472 -- check the stop condition under a lock before actually
@@ -518,11 +518,11 @@ abortExecution sv winfo = do
518--
518--
519processHeap
519processHeap
520 :: MonadRunInIO m
520 :: MonadRunInIO m
521− => IORef ([K.Stream m a], Int)
521+ => IORef ([K.StreamK m a], Int)
522− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)), Maybe Int)
522+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)), Maybe Int)
523 -> Channel m a
523 -> Channel m a
524 -> Maybe WorkerInfo
524 -> Maybe WorkerInfo
525− -> AheadHeapEntry K.Stream m a
525+ -> AheadHeapEntry K.StreamK m a
526 -> Int
526 -> Int
527 -> Bool -- we are draining the heap before we stop
527 -> Bool -- we are draining the heap before we stop
528 -> m ()
528 -> m ()
@@ -629,8 +629,8 @@ processHeap q heap sv winfo entry sno stopping = loopHeap sno entry
629{-# NOINLINE drainHeap #-}
629{-# NOINLINE drainHeap #-}
630drainHeap
630drainHeap
631 :: MonadRunInIO m
631 :: MonadRunInIO m
632− => IORef ([K.Stream m a], Int)
632+ => IORef ([K.StreamK m a], Int)
633− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)), Maybe Int)
633+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)), Maybe Int)
634 -> Channel m a
634 -> Channel m a
635 -> Maybe WorkerInfo
635 -> Maybe WorkerInfo
636 -> m ()
636 -> m ()
@@ -645,11 +645,11 @@ data HeapStatus = HContinue | HStop
645
645
646processWithoutToken
646processWithoutToken
647 :: MonadRunInIO m
647 :: MonadRunInIO m
648− => IORef ([K.Stream m a], Int)
648+ => IORef ([K.StreamK m a], Int)
649− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)), Maybe Int)
649+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)), Maybe Int)
650 -> Channel m a
650 -> Channel m a
651 -> Maybe WorkerInfo
651 -> Maybe WorkerInfo
652− -> K.Stream m a
652+ -> K.StreamK m a
653 -> Int
653 -> Int
654 -> m ()
654 -> m ()
655processWithoutToken q heap sv winfo m seqNo = do
655processWithoutToken q heap sv winfo m seqNo = do
@@ -725,11 +725,11 @@ data TokenWorkerStatus = TokenContinue Int | TokenSuspend
725
725
726processWithToken
726processWithToken
727 :: MonadRunInIO m
727 :: MonadRunInIO m
728− => IORef ([K.Stream m a], Int)
728+ => IORef ([K.StreamK m a], Int)
729− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)), Maybe Int)
729+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)), Maybe Int)
730 -> Channel m a
730 -> Channel m a
731 -> Maybe WorkerInfo
731 -> Maybe WorkerInfo
732− -> K.Stream m a
732+ -> K.StreamK m a
733 -> Int
733 -> Int
734 -> m ()
734 -> m ()
735processWithToken q heap sv winfo action sno = do
735processWithToken q heap sv winfo action sno = do
@@ -834,8 +834,8 @@ processWithToken q heap sv winfo action sno = do
834
834
835workLoopAhead
835workLoopAhead
836 :: MonadRunInIO m
836 :: MonadRunInIO m
837− => IORef ([K.Stream m a], Int)
837+ => IORef ([K.StreamK m a], Int)
838− -> IORef (Heap (Entry Int (AheadHeapEntry K.Stream m a)), Maybe Int)
838+ -> IORef (Heap (Entry Int (AheadHeapEntry K.StreamK m a)), Maybe Int)
839 -> Channel m a
839 -> Channel m a
840 -> Maybe WorkerInfo
840 -> Maybe WorkerInfo
841 -> m ()
841 -> m ()
@@ -897,8 +897,8 @@ getLifoSVar mrun cfg = do
897 wfw <- newIORef False
897 wfw <- newIORef False
898 running <- newIORef Set.empty
898 running <- newIORef Set.empty
899 q <- newIORef
899 q <- newIORef
900− ( [] :: [(RunInIO m, K.Stream m a)]
900+ ( [] :: [(RunInIO m, K.StreamK m a)]
901− , [] :: [(RunInIO m, K.Stream m a)]
901+ , [] :: [(RunInIO m, K.StreamK m a)]
902 )
902 )
903 -- Sequence number is incremented whenever something is de-queued,
903 -- Sequence number is incremented whenever something is de-queued,
904 -- therefore, first sequence number would be 0
904 -- therefore, first sequence number would be 0
@@ -936,7 +936,7 @@ getLifoSVar mrun cfg = do
936 -> (Channel m a -> m [ChildEvent a])
936 -> (Channel m a -> m [ChildEvent a])
937 -> (Channel m a -> m Bool)
937 -> (Channel m a -> m Bool)
938 -> (Channel m a -> IO Bool)
938 -> (Channel m a -> IO Bool)
939− -> (IORef ([(RunInIO m, K.Stream m a)], [(RunInIO m, K.Stream m a)])
939+ -> (IORef ([(RunInIO m, K.StreamK m a)], [(RunInIO m, K.StreamK m a)])
940 -> Channel m a
940 -> Channel m a
941 -> Maybe WorkerInfo
941 -> Maybe WorkerInfo
942 -> m())
942 -> m())
src/Streamly/Internal/Data/Stream/Concurrent/Channel/Interleave.hs+5−5
@@ -44,8 +44,8 @@ data WorkerStatus = Continue | Suspend
44{-# INLINE enqueueFIFO #-}
44{-# INLINE enqueueFIFO #-}
45enqueueFIFO ::
45enqueueFIFO ::
46 Channel m a
46 Channel m a
47− -> LinkedQueue (RunInIO m, K.Stream m a)
47+ -> LinkedQueue (RunInIO m, K.StreamK m a)
48− -> (RunInIO m, K.Stream m a)
48+ -> (RunInIO m, K.StreamK m a)
49 -> IO ()
49 -> IO ()
50enqueueFIFO sv q m = do
50enqueueFIFO sv q m = do
51 pushL q m
51 pushL q m
@@ -54,7 +54,7 @@ enqueueFIFO sv q m = do
54{-# INLINE workLoopFIFO #-}
54{-# INLINE workLoopFIFO #-}
55workLoopFIFO
55workLoopFIFO
56 :: MonadRunInIO m
56 :: MonadRunInIO m
57− => LinkedQueue (RunInIO m, K.Stream m a)
57+ => LinkedQueue (RunInIO m, K.StreamK m a)
58 -> Channel m a
58 -> Channel m a
59 -> Maybe WorkerInfo
59 -> Maybe WorkerInfo
60 -> m ()
60 -> m ()
@@ -93,7 +93,7 @@ workLoopFIFO q sv winfo = run
93{-# INLINE workLoopFIFOLimited #-}
93{-# INLINE workLoopFIFOLimited #-}
94workLoopFIFOLimited
94workLoopFIFOLimited
95 :: forall m a. MonadRunInIO m
95 :: forall m a. MonadRunInIO m
96− => LinkedQueue (RunInIO m, K.Stream m a)
96+ => LinkedQueue (RunInIO m, K.StreamK m a)
97 -> Channel m a
97 -> Channel m a
98 -> Maybe WorkerInfo
98 -> Maybe WorkerInfo
99 -> m ()
99 -> m ()
@@ -180,7 +180,7 @@ getFifoSVar mrun cfg = do
180 -> (Channel m a -> m [ChildEvent a])
180 -> (Channel m a -> m [ChildEvent a])
181 -> (Channel m a -> m Bool)
181 -> (Channel m a -> m Bool)
182 -> (Channel m a -> IO Bool)
182 -> (Channel m a -> IO Bool)
183− -> (LinkedQueue (RunInIO m, K.Stream m a)
183+ -> (LinkedQueue (RunInIO m, K.StreamK m a)
184 -> Channel m a
184 -> Channel m a
185 -> Maybe WorkerInfo
185 -> Maybe WorkerInfo
186 -> m())
186 -> m())
src/Streamly/Internal/Data/Stream/Concurrent/Channel/Operations.hs+3−3
@@ -89,7 +89,7 @@ import Test.Inspection (inspect, hasNoTypeClassesExcept)
89-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
89-- | Write a stream to an 'SVar' in a non-blocking manner. The stream can then
90-- be read back from the SVar using 'fromSVar'.
90-- be read back from the SVar using 'fromSVar'.
91{-# INLINE toChannelK #-}
91{-# INLINE toChannelK #-}
92−toChannelK :: MonadRunInIO m => Channel m a -> K.Stream m a -> m ()
92+toChannelK :: MonadRunInIO m => Channel m a -> K.StreamK m a -> m ()
93toChannelK sv m = do
93toChannelK sv m = do
94 runIn <- askRunInIO
94 runIn <- askRunInIO
95 liftIO $ enqueue sv False (runIn, m)
95 liftIO $ enqueue sv False (runIn, m)
@@ -114,7 +114,7 @@ joinChannel = undefined
114
114
115-- | Pull a stream from an SVar.
115-- | Pull a stream from an SVar.
116{-# NOINLINE fromChannelRaw #-}
116{-# NOINLINE fromChannelRaw #-}
117−fromChannelRaw :: (MonadIO m, MonadThrow m) => Channel m a -> K.Stream m a
117+fromChannelRaw :: (MonadIO m, MonadThrow m) => Channel m a -> K.StreamK m a
118fromChannelRaw sv = K.MkStream $ \st yld sng stp -> do
118fromChannelRaw sv = K.MkStream $ \st yld sng stp -> do
119 list <- readOutputQ sv
119 list <- readOutputQ sv
120 -- Reversing the output is important to guarantee that we process the
120 -- Reversing the output is important to guarantee that we process the
@@ -185,7 +185,7 @@ inspect $ hasNoTypeClassesExcept 'fromChannelRaw
185-- it to multiple consumers. or should we use an explicit dupChannel for that?
185-- it to multiple consumers. or should we use an explicit dupChannel for that?
186
186
187{-# INLINE fromChannelK #-}
187{-# INLINE fromChannelK #-}
188−fromChannelK :: MonadAsync m => Channel m a -> K.Stream m a
188+fromChannelK :: MonadAsync m => Channel m a -> K.StreamK m a
189fromChannelK sv =
189fromChannelK sv =
190 K.mkStream $ \st yld sng stp -> do
190 K.mkStream $ \st yld sng stp -> do
191 ref <- liftIO $ newIORef ()
191 ref <- liftIO $ newIORef ()
src/Streamly/Internal/Data/Stream/Concurrent/Channel/Type.hs+2−2
@@ -28,7 +28,7 @@ import Streamly.Internal.Data.Atomics (atomicModifyIORefCAS_)
28import Streamly.Internal.Data.Stream.Channel.Dispatcher (dumpSVarStats)
28import Streamly.Internal.Data.Stream.Channel.Dispatcher (dumpSVarStats)
29import Streamly.Internal.Data.Stream.Channel.Worker
29import Streamly.Internal.Data.Stream.Channel.Worker
30 (sendYield, sendStop, sendWithDoorBell)
30 (sendYield, sendStop, sendWithDoorBell)
31−import Streamly.Internal.Data.Stream.StreamK.Type (Stream)
31+import Streamly.Internal.Data.Stream.StreamK.Type (StreamK)
32
32
33import Streamly.Internal.Data.Stream.Channel.Types
33import Streamly.Internal.Data.Stream.Channel.Types
34
34
@@ -88,7 +88,7 @@ data Channel m a = Channel
88 , remainingWork :: Maybe (IORef Count)
88 , remainingWork :: Maybe (IORef Count)
89 , yieldRateInfo :: Maybe YieldRateInfo
89 , yieldRateInfo :: Maybe YieldRateInfo
90
90
91− , enqueue :: Bool -> (RunInIO m, Stream m a) -> IO ()
91+ , enqueue :: Bool -> (RunInIO m, StreamK m a) -> IO ()
92 , eagerDispatch :: m ()
92 , eagerDispatch :: m ()
93 , isWorkDone :: IO Bool
93 , isWorkDone :: IO Bool
94 , isQueueDone :: IO Bool
94 , isQueueDone :: IO Bool
src/Streamly/Internal/Data/Stream/IsStream/Type.hs+16−16
@@ -15,7 +15,7 @@ module Streamly.Internal.Data.Stream.IsStream.Type {-# DEPRECATED "Please use \"
15 (
15 (
16 -- * IsStream Type Class
16 -- * IsStream Type Class
17 IsStream (..)
17 IsStream (..)
18− , K.Stream (..)
18+ , K.StreamK (..)
19
19
20 -- * Type Conversion
20 -- * Type Conversion
21 , fromStreamD
21 , fromStreamD
@@ -124,7 +124,7 @@ import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
124 , drain, eqBy, cmpBy, fromList, toList, foldrMx, foldlMx'
124 , drain, eqBy, cmpBy, fromList, toList, foldrMx, foldlMx'
125 , foldlx', foldl', fold)
125 , foldlx', foldl', fold)
126import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
126import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
127− (Stream(..), cons, fromEffect
127+ (StreamK(..), cons, fromEffect
128 , nil, fromPure, bindWith, drain
128 , nil, fromPure, bindWith, drain
129 , fromFoldable, nilM, repeat)
129 , fromFoldable, nilM, repeat)
130import qualified Streamly.Internal.Data.Stream.StreamK as StreamK
130import qualified Streamly.Internal.Data.Stream.StreamK as StreamK
@@ -160,8 +160,8 @@ class
160 , forall m. MonadAsync m => Applicative (t m)
160 , forall m. MonadAsync m => Applicative (t m)
161 ) =>
161 ) =>
162 IsStream t where
162 IsStream t where
163− toStream :: t m a -> K.Stream m a
163+ toStream :: t m a -> K.StreamK m a
164− fromStream :: K.Stream m a -> t m a
164+ fromStream :: K.StreamK m a -> t m a
165 -- | Constructs a stream by adding a monadic action at the head of an
165 -- | Constructs a stream by adding a monadic action at the head of an
166 -- existing stream. For example:
166 -- existing stream. For example:
167 --
167 --
@@ -231,7 +231,7 @@ fromStreamD = fromStream . D.toStreamK
231-- | Adapt a polymorphic consM operation to a StreamK cons operation
231-- | Adapt a polymorphic consM operation to a StreamK cons operation
232{-# INLINE toConsK #-}
232{-# INLINE toConsK #-}
233toConsK :: IsStream t =>
233toConsK :: IsStream t =>
234− (m a -> t m a -> t m a) -> m a -> K.Stream m a -> K.Stream m a
234+ (m a -> t m a -> t m a) -> m a -> K.StreamK m a -> K.StreamK m a
235toConsK cns x xs = toStream $ x `cns` fromStream xs
235toConsK cns x xs = toStream $ x `cns` fromStream xs
236
236
237------------------------------------------------------------------------------
237------------------------------------------------------------------------------
@@ -317,7 +317,7 @@ toList m = D.toList $ toStreamD m
317-- continuation and a yield continuation.
317-- continuation and a yield continuation.
318{-# INLINE_EARLY mkStream #-}
318{-# INLINE_EARLY mkStream #-}
319mkStream :: IsStream t
319mkStream :: IsStream t
320− => (forall r. State K.Stream m a
320+ => (forall r. State K.StreamK m a
321 -> (a -> t m a -> m r)
321 -> (a -> t m a -> m r)
322 -> (a -> m r)
322 -> (a -> m r)
323 -> m r
323 -> m r
@@ -329,8 +329,8 @@ mkStream k = fromStream $ K.MkStream $ \st yld sng stp ->
329
329
330{-# RULES "mkStream from stream" mkStream = mkStreamFromStream #-}
330{-# RULES "mkStream from stream" mkStream = mkStreamFromStream #-}
331mkStreamFromStream :: IsStream t
331mkStreamFromStream :: IsStream t
332− => (forall r. State K.Stream m a
332+ => (forall r. State K.StreamK m a
333− -> (a -> K.Stream m a -> m r)
333+ -> (a -> K.StreamK m a -> m r)
334 -> (a -> m r)
334 -> (a -> m r)
335 -> m r
335 -> m r
336 -> m r)
336 -> m r)
@@ -339,12 +339,12 @@ mkStreamFromStream k = fromStream $ K.MkStream k
339
339
340{-# RULES "mkStream stream" mkStream = mkStreamStream #-}
340{-# RULES "mkStream stream" mkStream = mkStreamStream #-}
341mkStreamStream
341mkStreamStream
342− :: (forall r. State K.Stream m a
342+ :: (forall r. State K.StreamK m a
343− -> (a -> K.Stream m a -> m r)
343+ -> (a -> K.StreamK m a -> m r)
344 -> (a -> m r)
344 -> (a -> m r)
345 -> m r
345 -> m r
346 -> m r)
346 -> m r)
347− -> K.Stream m a
347+ -> K.StreamK m a
348mkStreamStream = K.MkStream
348mkStreamStream = K.MkStream
349
349
350------------------------------------------------------------------------------
350------------------------------------------------------------------------------
@@ -399,7 +399,7 @@ fold fld m = D.fold fld $ toStreamD m
399{-# INLINE_EARLY foldStreamShared #-}
399{-# INLINE_EARLY foldStreamShared #-}
400foldStreamShared
400foldStreamShared
401 :: IsStream t
401 :: IsStream t
402− => State K.Stream m a
402+ => State K.StreamK m a
403 -> (a -> t m a -> m r)
403 -> (a -> t m a -> m r)
404 -> (a -> m r)
404 -> (a -> m r)
405 -> m r
405 -> m r
@@ -414,11 +414,11 @@ foldStreamShared st yld sng stp m =
414{-# RULES "foldStreamShared from stream"
414{-# RULES "foldStreamShared from stream"
415 foldStreamShared = foldStreamSharedStream #-}
415 foldStreamShared = foldStreamSharedStream #-}
416foldStreamSharedStream
416foldStreamSharedStream
417− :: State K.Stream m a
417+ :: State K.StreamK m a
418− -> (a -> K.Stream m a -> m r)
418+ -> (a -> K.StreamK m a -> m r)
419 -> (a -> m r)
419 -> (a -> m r)
420 -> m r
420 -> m r
421− -> K.Stream m a
421+ -> K.StreamK m a
422 -> m r
422 -> m r
423foldStreamSharedStream st yld sng stp m =
423foldStreamSharedStream st yld sng stp m =
424 let K.MkStream k = m
424 let K.MkStream k = m
@@ -430,7 +430,7 @@ foldStreamSharedStream st yld sng stp m =
430{-# INLINE foldStream #-}
430{-# INLINE foldStream #-}
431foldStream
431foldStream
432 :: IsStream t
432 :: IsStream t
433− => State K.Stream m a
433+ => State K.StreamK m a
434 -> (a -> t m a -> m r)
434 -> (a -> t m a -> m r)
435 -> (a -> m r)
435 -> (a -> m r)
436 -> m r
436 -> m r
src/Streamly/Internal/Data/Stream/Parallel.hs+16−16
@@ -65,7 +65,7 @@ import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
65
65
66import qualified Data.Set as Set
66import qualified Data.Set as Set
67import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
67import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
68− (Stream, foldStreamShared, mkStream, foldStream, fromEffect
68+ (StreamK, foldStreamShared, mkStream, foldStream, fromEffect
69 , nil, concatMapWith, fromPure, bindWith)
69 , nil, concatMapWith, fromPure, bindWith)
70import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
70import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
71 (Stream(..), mapM, toStreamK, fromStreamK)
71 (Stream(..), mapM, toStreamK, fromStreamK)
@@ -91,7 +91,7 @@ import Prelude hiding (map)
91-- :}
91-- :}
92
92
93{-# INLINABLE withLocal #-}
93{-# INLINABLE withLocal #-}
94−withLocal :: MonadReader r m => (r -> r) -> K.Stream m a -> K.Stream m a
94+withLocal :: MonadReader r m => (r -> r) -> K.StreamK m a -> K.StreamK m a
95withLocal f m =
95withLocal f m =
96 K.mkStream $ \st yld sng stp ->
96 K.mkStream $ \st yld sng stp ->
97 let single = local f . sng
97 let single = local f . sng
@@ -109,7 +109,7 @@ withLocal f m =
109{-# NOINLINE runOne #-}
109{-# NOINLINE runOne #-}
110runOne
110runOne
111 :: MonadIO m
111 :: MonadIO m
112− => State K.Stream m a -> K.Stream m a -> Maybe WorkerInfo -> m ()
112+ => State K.StreamK m a -> K.StreamK m a -> Maybe WorkerInfo -> m ()
113runOne st m0 winfo =
113runOne st m0 winfo =
114 case getYieldLimit st of
114 case getYieldLimit st of
115 Nothing -> go m0
115 Nothing -> go m0
@@ -132,7 +132,7 @@ runOne st m0 winfo =
132
132
133runOneLimited
133runOneLimited
134 :: MonadIO m
134 :: MonadIO m
135− => State K.Stream m a -> K.Stream m a -> Maybe WorkerInfo -> m ()
135+ => State K.StreamK m a -> K.StreamK m a -> Maybe WorkerInfo -> m ()
136runOneLimited st m0 winfo = go m0
136runOneLimited st m0 winfo = go m0
137
137
138 where
138 where
@@ -169,7 +169,7 @@ runOneLimited st m0 winfo = go m0
169
169
170{-# NOINLINE forkSVarPar #-}
170{-# NOINLINE forkSVarPar #-}
171forkSVarPar :: MonadAsync m
171forkSVarPar :: MonadAsync m
172− => SVarStopStyle -> K.Stream m a -> K.Stream m a -> K.Stream m a
172+ => SVarStopStyle -> K.StreamK m a -> K.StreamK m a -> K.StreamK m a
173forkSVarPar ss m r = K.mkStream $ \st yld sng stp -> do
173forkSVarPar ss m r = K.mkStream $ \st yld sng stp -> do
174 sv <- newParallelVar ss st
174 sv <- newParallelVar ss st
175 pushWorkerPar sv (runOne st{streamVar = Just sv} m)
175 pushWorkerPar sv (runOne st{streamVar = Just sv} m)
@@ -186,9 +186,9 @@ joinStreamVarPar ::
186 MonadAsync m
186 MonadAsync m
187 => SVarStyle
187 => SVarStyle
188 -> SVarStopStyle
188 -> SVarStopStyle
189− -> K.Stream m a
189+ -> K.StreamK m a
190− -> K.Stream m a
190+ -> K.StreamK m a
191− -> K.Stream m a
191+ -> K.StreamK m a
192joinStreamVarPar style ss m1 m2 = K.mkStream $ \st yld sng stp ->
192joinStreamVarPar style ss m1 m2 = K.mkStream $ \st yld sng stp ->
193 case streamVar st of
193 case streamVar st of
194 Just sv | svarStyle sv == style && svarStopStyle sv == ss -> do
194 Just sv | svarStyle sv == style && svarStopStyle sv == ss -> do
@@ -238,7 +238,7 @@ joinStreamVarPar style ss m1 m2 = K.mkStream $ \st yld sng stp ->
238-------------------------------------------------------------------------------
238-------------------------------------------------------------------------------
239
239
240{-# INLINE parallelK #-}
240{-# INLINE parallelK #-}
241−parallelK :: MonadAsync m => K.Stream m a -> K.Stream m a -> K.Stream m a
241+parallelK :: MonadAsync m => K.StreamK m a -> K.StreamK m a -> K.StreamK m a
242parallelK = joinStreamVarPar ParallelVar StopNone
242parallelK = joinStreamVarPar ParallelVar StopNone
243
243
244-- | XXX we can implement it more efficienty by directly implementing instead
244-- | XXX we can implement it more efficienty by directly implementing instead
@@ -256,7 +256,7 @@ consM m (ParallelT r) = ParallelT $ parallelK (K.fromEffect m) r
256--
256--
257-- /Pre-release/
257-- /Pre-release/
258{-# INLINE parallelFstK #-}
258{-# INLINE parallelFstK #-}
259−parallelFstK :: MonadAsync m => K.Stream m a -> K.Stream m a -> K.Stream m a
259+parallelFstK :: MonadAsync m => K.StreamK m a -> K.StreamK m a -> K.StreamK m a
260parallelFstK = joinStreamVarPar ParallelVar StopBy
260parallelFstK = joinStreamVarPar ParallelVar StopBy
261
261
262-- This is a race like combinator for streams.
262-- This is a race like combinator for streams.
@@ -266,7 +266,7 @@ parallelFstK = joinStreamVarPar ParallelVar StopBy
266--
266--
267-- /Pre-release/
267-- /Pre-release/
268{-# INLINE parallelMinK #-}
268{-# INLINE parallelMinK #-}
269−parallelMinK :: MonadAsync m => K.Stream m a -> K.Stream m a -> K.Stream m a
269+parallelMinK :: MonadAsync m => K.StreamK m a -> K.StreamK m a -> K.StreamK m a
270parallelMinK = joinStreamVarPar ParallelVar StopAny
270parallelMinK = joinStreamVarPar ParallelVar StopAny
271
271
272------------------------------------------------------------------------------
272------------------------------------------------------------------------------
@@ -277,7 +277,7 @@ parallelMinK = joinStreamVarPar ParallelVar StopAny
277--
277--
278-- /Pre-release/
278-- /Pre-release/
279--
279--
280−mkParallelK :: MonadAsync m => K.Stream m a -> K.Stream m a
280+mkParallelK :: MonadAsync m => K.StreamK m a -> K.StreamK m a
281mkParallelK m = K.mkStream $ \st yld sng stp -> do
281mkParallelK m = K.mkStream $ \st yld sng stp -> do
282 sv <- newParallelVar StopNone (adaptState st)
282 sv <- newParallelVar StopNone (adaptState st)
283 -- pushWorkerPar sv (runOne st{streamVar = Just sv} $ toStream m)
283 -- pushWorkerPar sv (runOne st{streamVar = Just sv} $ toStream m)
@@ -327,7 +327,7 @@ mkParallelD m = D.Stream step Nothing
327-- is determined by the prevailing 'Streamly.Prelude.maxBuffer' setting.
327-- is determined by the prevailing 'Streamly.Prelude.maxBuffer' setting.
328--
328--
329-- @
329-- @
330−-- Stream m a -> m b
330+-- StreamK m a -> m b
331-- |
331-- |
332-- -----stream m a ---------------stream m a-----
332-- -----stream m a ---------------stream m a-----
333--
333--
@@ -351,7 +351,7 @@ mkParallelD m = D.Stream step Nothing
351-- /Pre-release/
351-- /Pre-release/
352{-# INLINE tapAsyncK #-}
352{-# INLINE tapAsyncK #-}
353tapAsyncK ::
353tapAsyncK ::
354− MonadAsync m => (K.Stream m a -> m b) -> K.Stream m a -> K.Stream m a
354+ MonadAsync m => (K.StreamK m a -> m b) -> K.StreamK m a -> K.StreamK m a
355tapAsyncK f m = K.mkStream $ \st yld sng stp -> do
355tapAsyncK f m = K.mkStream $ \st yld sng stp -> do
356 sv <- SVar.newFoldSVar st (f . Stream.toStreamK)
356 sv <- SVar.newFoldSVar st (f . Stream.toStreamK)
357 K.foldStreamShared st yld sng stp
357 K.foldStreamShared st yld sng stp
@@ -429,7 +429,7 @@ tapAsyncF f (D.Stream step1 state1) = D.Stream step TapInit
429-- /Since: 0.7.0 (maxBuffer applies to ParallelT streams)/
429-- /Since: 0.7.0 (maxBuffer applies to ParallelT streams)/
430--
430--
431-- @since 0.8.0
431-- @since 0.8.0
432−newtype ParallelT m a = ParallelT {getParallelT :: K.Stream m a}
432+newtype ParallelT m a = ParallelT {getParallelT :: K.StreamK m a}
433
433
434instance MonadTrans ParallelT where
434instance MonadTrans ParallelT where
435 {-# INLINE lift #-}
435 {-# INLINE lift #-}
@@ -519,7 +519,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
519-- /Pre-release/
519-- /Pre-release/
520--
520--
521{-# INLINE_NORMAL newCallbackStream #-}
521{-# INLINE_NORMAL newCallbackStream #-}
522−newCallbackStream :: MonadAsync m => m (a -> m (), K.Stream m a)
522+newCallbackStream :: MonadAsync m => m (a -> m (), K.StreamK m a)
523newCallbackStream = do
523newCallbackStream = do
524 sv <- newParallelVar StopNone defState
524 sv <- newParallelVar StopNone defState
525
525
src/Streamly/Internal/Data/Stream/SVar/Eliminate.hs+1−1
@@ -43,7 +43,7 @@ import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
43import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
43import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
44 (Stream(..), Step(..), fold)
44 (Stream(..), Step(..), fold)
45import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
45import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
46− (Stream(..), mkStream, foldStream, foldStreamShared, nilM)
46+ (Stream, mkStream, foldStream, foldStreamShared, nilM)
47import qualified Streamly.Internal.Data.Stream.Serial as Stream
47import qualified Streamly.Internal.Data.Stream.Serial as Stream
48 (fromStreamK, toStreamK)
48 (fromStreamK, toStreamK)
49
49
src/Streamly/Internal/Data/Stream/SVar/Generate.hs+4−4
@@ -46,7 +46,7 @@ import System.Mem (performMajorGC)
46import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
46import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
47 (Stream(..), Step(..))
47 (Stream(..), Step(..))
48import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
48import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
49− (Stream(..), foldStreamShared, mkStream, foldStream)
49+ (Stream, foldStreamShared, mkStream, foldStream)
50import qualified Streamly.Internal.Data.Stream.Serial as Stream (fromStreamK)
50import qualified Streamly.Internal.Data.Stream.Serial as Stream (fromStreamK)
51
51
52import Streamly.Internal.Data.SVar
52import Streamly.Internal.Data.SVar
@@ -113,7 +113,7 @@ toSVar sv m = do
113-- | Pull a stream from an SVar.
113-- | Pull a stream from an SVar.
114{-# NOINLINE fromStreamVar #-}
114{-# NOINLINE fromStreamVar #-}
115fromStreamVar :: MonadAsync m => SVar K.Stream m a -> K.Stream m a
115fromStreamVar :: MonadAsync m => SVar K.Stream m a -> K.Stream m a
116−fromStreamVar sv = K.MkStream $ \st yld sng stp -> do
116+fromStreamVar sv = K.mkStream $ \st yld sng stp -> do
117 list <- readOutputQ sv
117 list <- readOutputQ sv
118 -- Reversing the output is important to guarantee that we process the
118 -- Reversing the output is important to guarantee that we process the
119 -- outputs in the same order as they were generated by the constituent
119 -- outputs in the same order as they were generated by the constituent
@@ -130,13 +130,13 @@ fromStreamVar sv = K.MkStream $ \st yld sng stp -> do
130 stp
130 stp
131
131
132 {-# INLINE processEvents #-}
132 {-# INLINE processEvents #-}
133− processEvents [] = K.MkStream $ \st yld sng stp -> do
133+ processEvents [] = K.mkStream $ \st yld sng stp -> do
134 done <- postProcess sv
134 done <- postProcess sv
135 if done
135 if done
136 then allDone stp
136 then allDone stp
137 else K.foldStream st yld sng stp $ fromStreamVar sv
137 else K.foldStream st yld sng stp $ fromStreamVar sv
138
138
139− processEvents (ev : es) = K.MkStream $ \st yld sng stp -> do
139+ processEvents (ev : es) = K.mkStream $ \st yld sng stp -> do
140 let rest = processEvents es
140 let rest = processEvents es
141 case ev of
141 case ev of
142 ChildYield a -> yld a rest
142 ChildYield a -> yld a rest
src/Streamly/Internal/Data/Stream/Serial.hs+1−1
@@ -1,5 +1,5 @@
1{-# LANGUAGE UndecidableInstances #-}
1{-# LANGUAGE UndecidableInstances #-}
2−{-# OPTIONS_GHC -Wno-orphans #-}
2+{-# OPTIONS_GHC -Wno-deprecations #-}
3
3
4-- |
4-- |
5-- Module : Streamly.Internal.Data.Stream.Serial
5-- Module : Streamly.Internal.Data.Stream.Serial
src/inline.hs+1−1
@@ -16,7 +16,7 @@
16-- Then, fromStreamK/toStreamK are inlined in the last phase:
16-- Then, fromStreamK/toStreamK are inlined in the last phase:
17--
17--
18-- {-# INLINE_LATE toStreamK #-}
18-- {-# INLINE_LATE toStreamK #-}
19−-- toStreamK :: Monad m => Stream m a -> K.Stream m a```
19+-- toStreamK :: Monad m => Stream m a -> K.StreamK m a```
20--
20--
21-- The fallback rules make sure that if we could not fuse the direct style
21-- The fallback rules make sure that if we could not fuse the direct style
22-- operations then better use the CPS style operation, because unfused direct
22-- operations then better use the CPS style operation, because unfused direct