@@ -15,8 +15,8 @@
15module Streamly.Internal.Data.Stream.StreamK.Type
15module Streamly.Internal.Data.Stream.StreamK.Type
17 -- * StreamK type
17 -- * StreamK type
18− Stream (..) -- XXX stop exporting this
18+ Stream
19− , StreamK
19+ , StreamK (..)
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:
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)
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
204-- >>> (<>) = Stream.append
204-- >>> (<>) = Stream.append
206−type StreamK = Stream
206+{-# DEPRECATED Stream "Please use StreamK instead." #-}
207+type Stream = StreamK
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
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)
223− -> Stream m a
224+ -> StreamK m a
224mkStream = MkStream
225mkStream = MkStream
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 >>=)
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
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
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)
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
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
280infixr 5 .:
281infixr 5 .:
@@ -288,7 +289,7 @@ infixr 5 .:
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
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 .:
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
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
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
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
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
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
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
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
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)
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
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)
382− -> Stream m a
383+ -> StreamK m a
384foldStreamShared s yield single stop (MkStream k) = k s yield single stop
385foldStreamShared s yield single stop (MkStream k) = k s yield single stop
@@ -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)
395− -> Stream m a
396+ -> StreamK m a
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) =
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)
416− -> Stream m b
417+ -> StreamK m b
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
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
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:
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]
484-- /Pre-release/
485-- /Pre-release/
485{-# INLINE_NORMAL foldrS #-}
486{-# INLINE_NORMAL foldrS #-}
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
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
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)
512− -> Stream m b
513+ -> StreamK m b
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
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
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
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
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-------------------------------------------------------------------------------
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
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 #-}
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
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 #-}
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) #-}
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 #-}
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) #-}
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
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 #-}
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 #-}
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)
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
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)
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
@@ -668,50 +669,50 @@ sharedMWith cns g = mkStream $ \st yld sng stp ->
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
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
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)
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))
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
699{-# RULES "augmentSM/nil"
700{-# RULES "augmentSM/nil"
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
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)
711{-# RULES "augmentSM/buildSM"
712{-# RULES "augmentSM/buildSM"
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))
@@ -721,7 +722,7 @@ augmentSM g xs = g consM xs
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
@@ -732,15 +733,15 @@ foldrM step acc m = go m
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)
739− -> Stream m a
740+ -> StreamK m a
741 -> (a -> m b -> m b)
742 -> (a -> m b -> 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)
745foldrMKWith f step acc = go
746foldrMKWith f step acc = go
@@ -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)
@@ -771,7 +772,7 @@ foldrMKWith f step acc = go
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)
@@ -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
798 {-# NOINLINE get #-}
799 {-# NOINLINE get #-}
799− get :: Stream m x -> m b
800+ get :: StreamK m x -> m b
801 -- XXX we are not strictly evaluating the accumulator here. Is this
802 -- XXX we are not strictly evaluating the accumulator here. Is this
@@ -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
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
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 ())
842drain = go
843drain = go
@@ -849,7 +850,7 @@ drain = go
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)
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.
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
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)
895−instance Semigroup (Stream m a) where
896+instance Semigroup (StreamK m a) where
896 (<>) = append
897 (<>) = append
898------------------------------------------------------------------------------
899------------------------------------------------------------------------------
900------------------------------------------------------------------------------
901------------------------------------------------------------------------------
902−instance Monoid (Stream m a) where
903+instance Monoid (StreamK m a) where
903 mempty = nil
904 mempty = nil
904 mappend = (<>)
905 mappend = (<>)
@@ -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)
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
@@ -925,7 +926,7 @@ mapFB c f = \x ys -> c (f x) ys
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)
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)
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
@@ -987,7 +988,7 @@ mapMWith cns f = go
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
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
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
1009 {-# INLINE fromList #-}
1010 {-# INLINE fromList #-}
1010 fromList = fromFoldable
1011 fromList = fromFoldable
@@ -1014,11 +1015,11 @@ instance IsList (Stream Identity a) where
1015-- XXX Fix these
1016-- XXX Fix these
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
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
@@ -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
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)
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
1065 readListPrec = readListPrecDefault
1066 readListPrec = readListPrecDefault
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
@@ -1074,7 +1075,7 @@ instance (a ~ Char) => IsString (Stream Identity a) where
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)
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.
1087−instance (Foldable m, Monad m) => Foldable (Stream m) where
1088+instance (Foldable m, Monad m) => Foldable (StreamK m) where
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-------------------------------------------------------------------------------
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
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
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
@@ -1192,9 +1193,9 @@ crossApplyWith par fstream stream = go1 fstream
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
@@ -1222,9 +1223,9 @@ crossApply fstream stream = go1 fstream
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
@@ -1246,9 +1247,9 @@ crossApplySnd fstream stream = go1 fstream
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
@@ -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.
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
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)@.
1291-- Definition:
1292-- Definition:
@@ -1304,7 +1305,7 @@ crossWith f m1 m2 = fmap f m1 `crossApply` m2
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 (,)
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
@@ -1341,14 +1342,14 @@ bindWith par m1 f = go m1
1341{-# INLINE concatMapWith #-}
1342{-# INLINE concatMapWith #-}
1342concatMapWith
1343concatMapWith
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
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
@@ -1392,10 +1393,10 @@ concatMap_ f xs = buildS
1392{-# INLINE mergeMapWith #-}
1393{-# INLINE mergeMapWith #-}
1393mergeMapWith
1394mergeMapWith
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)
@@ -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
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
@@ -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
@@ -1506,10 +1507,10 @@ concatUnfoldr = undefined
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
@@ -1532,10 +1533,10 @@ concatIterateWith combine f = iterateStream
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
@@ -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))
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 =
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
@@ -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))
@@ -1650,7 +1651,7 @@ infixr 6 `interleave`
1650-- streams.
1651-- streams.
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.
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.
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-------------------------------------------------------------------------------
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 ->
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)))
1712− -> Stream m a
1713+ -> StreamK m a
1713unfoldrMWith cns step = go
1714unfoldrMWith cns step = go
@@ -1721,14 +1722,14 @@ unfoldrMWith cns step = go
1721 Nothing -> stp
1722 Nothing -> stp
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
1727-- | Generate an infinite stream by repeating a pure value.
1728-- | Generate an infinite stream by repeating a pure value.
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
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
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
@@ -1753,7 +1754,7 @@ replicateMWith cns n m = go n
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
@@ -1763,7 +1764,7 @@ fromIndicesMWith cns gen = go 0
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
@@ -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))
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")
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 ->
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 ->
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
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
1872-------------------------------------------------------------------------------
1873-------------------------------------------------------------------------------
@@ -1874,7 +1875,7 @@ fromFoldableM = Prelude.foldr consM nil
1874-------------------------------------------------------------------------------
1875-------------------------------------------------------------------------------
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
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))
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 =
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
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
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
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
1931------------------------------------------------------------------------------
1932------------------------------------------------------------------------------
@@ -1934,20 +1935,20 @@ reverse = foldlS (flip cons) nil
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
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
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 =
1981-- [(1,3),(1,4),(2,3),(2,4)]
1982-- [(1,3),(1,4),(2,3),(2,4)]
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)
1986-- | Wrap the 'StreamK' type in a 'CrossStreamK' newtype to enable cross
1987-- | Wrap the 'StreamK' type in a 'CrossStreamK' newtype to enable cross