@@ -15,8 +15,8 @@
1515module Streamly.Internal.Data.Stream.StreamK.Type
1616 (
1717 -- * StreamK type
18− Stream (..) -- XXX stop exporting this
19− , StreamK
18+ Stream
19+ , StreamK (..)
2020
2121 -- * CrossStreamK type wrapper
2222 , CrossStreamK
@@ -181,7 +181,7 @@ import Prelude hiding
181181-- direct style type:
182182--
183183-- @
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)
185185-- @
186186--
187187-- To facilitate parallel composition we maintain a local state in an 'SVar'
@@ -203,24 +203,25 @@ import Prelude hiding
203203--
204204-- >>> (<>) = Stream.append
205205--
206−type StreamK = Stream
206+{-# DEPRECATED Stream "Please use StreamK instead." #-}
207+type Stream = StreamK
207208
208−newtype Stream m a =
209+newtype StreamK m a =
209210 MkStream (forall r.
210− State Stream m a -- state
211− -> (a -> Stream m a -> m r) -- yield
211+ State StreamK m a -- state
212+ -> (a -> StreamK m a -> m r) -- yield
212213 -> (a -> m r) -- singleton
213214 -> m r -- stop
214215 -> m r
215216 )
216217
217218mkStream
218− :: (forall r. State Stream m a
219− -> (a -> Stream m a -> m r)
219+ :: (forall r. State StreamK m a
220+ -> (a -> StreamK m a -> m r)
220221 -> (a -> m r)
221222 -> m r
222223 -> m r)
223− -> Stream m a
224+ -> StreamK m a
224225mkStream = MkStream
225226
226227-- | A terminal function that has no continuation to follow.
@@ -236,16 +237,16 @@ _wrapM :: Monad m => m a -> YieldK m a
236237_wrapM m = (m >>=)
237238
238239-- | Make an empty stream from a stop function.
239−fromStopK :: StopK m -> Stream m a
240+fromStopK :: StopK m -> StreamK m a
240241fromStopK k = mkStream $ \_ _ _ stp -> k stp
241242
242243-- | Make a singleton stream from a callback function. The callback function
243244-- 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
245246fromYieldK k = mkStream $ \_ _ sng _ -> k sng
246247
247248-- | 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
249250consK k r = mkStream $ \_ yld _ _ -> k (`yld` r)
250251
251252-- XXX Build a stream from a repeating callback function.
@@ -274,7 +275,7 @@ infixr 5 `cons`
274275-- >>> cons x xs = return x `StreamK.consM` xs
275276--
276277{-# INLINE_NORMAL cons #-}
277−cons :: a -> Stream m a -> Stream m a
278+cons :: a -> StreamK m a -> StreamK m a
278279cons a r = mkStream $ \_ yield _ _ -> yield a r
279280
280281infixr 5 .:
@@ -288,7 +289,7 @@ infixr 5 .:
288289--
289290-- @since 0.1.1
290291{-# INLINE (.:) #-}
291−(.:) :: a -> Stream m a -> Stream m a
292+(.:) :: a -> StreamK m a -> StreamK m a
292293(.:) = cons
293294
294295-- | A stream that terminates without producing any output or side effect.
@@ -297,7 +298,7 @@ infixr 5 .:
297298-- []
298299--
299300{-# INLINE_NORMAL nil #-}
300−nil :: Stream m a
301+nil :: StreamK m a
301302nil = mkStream $ \_ _ _ stp -> stp
302303
303304-- | A stream that terminates without producing any output, but produces a side
@@ -309,7 +310,7 @@ nil = mkStream $ \_ _ _ stp -> stp
309310--
310311-- /Pre-release/
311312{-# INLINE_NORMAL nilM #-}
312−nilM :: Applicative m => m b -> Stream m a
313+nilM :: Applicative m => m b -> StreamK m a
313314nilM m = mkStream $ \_ _ _ stp -> m *> stp
314315
315316-- | Create a singleton stream from a pure value.
@@ -319,7 +320,7 @@ nilM m = mkStream $ \_ _ _ stp -> m *> stp
319320-- >>> fromPure = StreamK.fromEffect . pure
320321--
321322{-# INLINE_NORMAL fromPure #-}
322−fromPure :: a -> Stream m a
323+fromPure :: a -> StreamK m a
323324fromPure a = mkStream $ \_ _ single _ -> single a
324325
325326-- | Create a singleton stream from a monadic action.
@@ -330,7 +331,7 @@ fromPure a = mkStream $ \_ _ single _ -> single a
330331-- hello
331332--
332333{-# INLINE_NORMAL fromEffect #-}
333−fromEffect :: Monad m => m a -> Stream m a
334+fromEffect :: Monad m => m a -> StreamK m a
334335fromEffect m = mkStream $ \_ _ single _ -> m >>= single
335336
336337infixr 5 `consM`
@@ -356,14 +357,14 @@ infixr 5 `consM`
356357-- >>> consM x xs = StreamK.fromEffect x `StreamK.append` xs
357358--
358359{-# INLINE consM #-}
359−{-# SPECIALIZE consM :: IO a -> Stream IO a -> Stream IO a #-}
360−consM :: Monad m => m a -> Stream m a -> Stream m a
360+{-# SPECIALIZE consM :: IO a -> StreamK IO a -> StreamK IO a #-}
361+consM :: Monad m => m a -> StreamK m a -> StreamK m a
361362consM m r = MkStream $ \_ yld _ _ -> m >>= (`yld` r)
362363
363364-- XXX specialize to IO?
364365{-# INLINE consMBy #-}
365366consMBy :: 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
367368consMBy f m r = fromEffect m `f` r
368369
369370------------------------------------------------------------------------------
@@ -375,11 +376,11 @@ consMBy f m r = fromEffect m `f` r
375376-- SVar passed via the State.
376377{-# INLINE_EARLY foldStreamShared #-}
377378foldStreamShared
378− :: State Stream m a
379− -> (a -> Stream m a -> m r)
379+ :: State StreamK m a
380+ -> (a -> StreamK m a -> m r)
380381 -> (a -> m r)
381382 -> m r
382− -> Stream m a
383+ -> StreamK m a
383384 -> m r
384385foldStreamShared s yield single stop (MkStream k) = k s yield single stop
385386
@@ -388,11 +389,11 @@ foldStreamShared s yield single stop (MkStream k) = k s yield single stop
388389-- passed via State.
389390{-# INLINE foldStream #-}
390391foldStream
391− :: State Stream m a
392− -> (a -> Stream m a -> m r)
392+ :: State StreamK m a
393+ -> (a -> StreamK m a -> m r)
393394 -> (a -> m r)
394395 -> m r
395− -> Stream m a
396+ -> StreamK m a
396397 -> m r
397398foldStream s yield single stop (MkStream k) =
398399 k (adaptState s) yield single stop
@@ -409,16 +410,16 @@ foldStream s yield single stop (MkStream k) =
409410--
410411{-# INLINE foldrSWith #-}
411412foldrSWith ::
412− (forall r. State Stream m b
413− -> (b -> Stream m b -> m r)
413+ (forall r. State StreamK m b
414+ -> (b -> StreamK m b -> m r)
414415 -> (b -> m r)
415416 -> m r
416− -> Stream m b
417+ -> StreamK m b
417418 -> m r)
418− -> (a -> Stream m b -> Stream m b)
419− -> Stream m b
420− -> Stream m a
421− -> Stream m b
419+ -> (a -> StreamK m b -> StreamK m b)
420+ -> StreamK m b
421+ -> StreamK m a
422+ -> StreamK m b
422423foldrSWith f step final m = go m
423424 where
424425 go m1 = mkStream $ \st yld sng stp ->
@@ -438,10 +439,10 @@ foldrSWith f step final m = go m
438439-- | Fold sharing the SVar state within the reconstructed stream
439440{-# INLINE_NORMAL foldrSShared #-}
440441foldrSShared ::
441− (a -> Stream m b -> Stream m b)
442− -> Stream m b
443− -> Stream m a
444− -> Stream m b
442+ (a -> StreamK m b -> StreamK m b)
443+ -> StreamK m b
444+ -> StreamK m a
445+ -> StreamK m b
445446foldrSShared = foldrSWith foldStreamShared
446447
447448-- XXX consM is a typeclass method, therefore rewritten already. Instead maybe
@@ -477,17 +478,17 @@ foldrSShared = foldrSWith foldStreamShared
477478-- Map (+2) on odd elements and filter out the even elements:
478479--
479480-- >>> 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
481482-- >>> Stream.fold Fold.toList $ StreamK.toStream $ StreamK.foldrS step StreamK.nil input
482483-- [3,5,7]
483484--
484485-- /Pre-release/
485486{-# INLINE_NORMAL foldrS #-}
486487foldrS ::
487− (a -> Stream m b -> Stream m b)
488− -> Stream m b
489− -> Stream m a
490− -> Stream m b
488+ (a -> StreamK m b -> StreamK m b)
489+ -> StreamK m b
490+ -> StreamK m a
491+ -> StreamK m b
491492foldrS = foldrSWith foldStream
492493
493494{-# RULES "foldrS/id" foldrS cons nil = \x -> x #-}
@@ -505,16 +506,16 @@ foldrS = foldrSWith foldStream
505506
506507{-# INLINE foldrSMWith #-}
507508foldrSMWith :: Monad m
508− => (forall r. State Stream m b
509− -> (b -> Stream m b -> m r)
509+ => (forall r. State StreamK m b
510+ -> (b -> StreamK m b -> m r)
510511 -> (b -> m r)
511512 -> m r
512− -> Stream m b
513+ -> StreamK m b
513514 -> m r)
514− -> (m a -> Stream m b -> Stream m b)
515− -> Stream m b
516− -> Stream m a
517− -> Stream m b
515+ -> (m a -> StreamK m b -> StreamK m b)
516+ -> StreamK m b
517+ -> StreamK m a
518+ -> StreamK m b
518519foldrSMWith f step final m = go m
519520 where
520521 go m1 = mkStream $ \st yld sng stp ->
@@ -526,10 +527,10 @@ foldrSMWith f step final m = go m
526527
527528{-# INLINE_NORMAL foldrSM #-}
528529foldrSM :: Monad m
529− => (m a -> Stream m b -> Stream m b)
530− -> Stream m b
531− -> Stream m a
532− -> Stream m b
530+ => (m a -> StreamK m b -> StreamK m b)
531+ -> StreamK m b
532+ -> StreamK m a
533+ -> StreamK m b
533534foldrSM = foldrSMWith foldStream
534535
535536-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
@@ -541,10 +542,10 @@ foldrSM = foldrSMWith foldStream
541542-- Like foldrSM but sharing the SVar state within the recostructed stream.
542543{-# INLINE_NORMAL foldrSMShared #-}
543544foldrSMShared :: Monad m
544− => (m a -> Stream m b -> Stream m b)
545− -> Stream m b
546− -> Stream m a
547− -> Stream m b
545+ => (m a -> StreamK m b -> StreamK m b)
546+ -> StreamK m b
547+ -> StreamK m a
548+ -> StreamK m b
548549foldrSMShared = foldrSMWith foldStreamShared
549550
550551-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
@@ -560,7 +561,7 @@ foldrSMShared = foldrSMWith foldStreamShared
560561-------------------------------------------------------------------------------
561562
562563{-# 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
564565build g = g cons nil
565566
566567{-# RULES "foldrM/build"
@@ -586,45 +587,45 @@ build g = g cons nil
586587-- build a stream by applying cons and nil to a build function
587588{-# INLINE_NORMAL buildS #-}
588589buildS ::
589− ((a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
590− -> Stream m a
590+ ((a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
591+ -> StreamK m a
591592buildS g = g cons nil
592593
593594{-# RULES "foldrS/buildS"
594595 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).
596597 foldrS k z (buildS g) = g k z #-}
597598
598599{-# RULES "foldrS/cons/buildS"
599600 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).
601602 foldrS k z (x `cons` buildS g) = k x (g k z) #-}
602603
603604{-# RULES "foldrSShared/buildS"
604605 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).
606607 foldrSShared k z (buildS g) = g k z #-}
607608
608609{-# RULES "foldrSShared/cons/buildS"
609610 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).
611612 foldrSShared k z (x `cons` buildS g) = k x (g k z) #-}
612613
613614-- build a stream by applying consM and nil to a build function
614615{-# INLINE_NORMAL buildSM #-}
615616buildSM :: Monad m
616− => ((m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
617− -> Stream m a
617+ => ((m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
618+ -> StreamK m a
618619buildSM g = g consM nil
619620
620621{-# RULES "foldrSM/buildSM"
621622 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).
623624 foldrSM k z (buildSM g) = g k z #-}
624625
625626{-# RULES "foldrSMShared/buildSM"
626627 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).
628629 foldrSMShared k z (buildSM g) = g k z #-}
629630
630631-- Disabled because this may not fire as consM is a class Op
@@ -640,25 +641,25 @@ buildSM g = g consM nil
640641-- reconstructing a stream.
641642{-# INLINE_NORMAL buildM #-}
642643buildM :: Monad m
643− => (forall r. (a -> Stream m a -> m r)
644+ => (forall r. (a -> StreamK m a -> m r)
644645 -> (a -> m r)
645646 -> m r
646647 -> m r
647648 )
648− -> Stream m a
649+ -> StreamK m a
649650buildM g = mkStream $ \st yld sng stp ->
650651 g (\a r -> foldStream st yld sng stp (return a `consM` r)) sng stp
651652
652653-- | Like 'buildM' but shares the SVar state across computations.
653654{-# INLINE_NORMAL sharedMWith #-}
654655sharedMWith :: Monad m
655− => (m a -> Stream m a -> Stream m a)
656− -> (forall r. (a -> Stream m a -> m r)
656+ => (m a -> StreamK m a -> StreamK m a)
657+ -> (forall r. (a -> StreamK m a -> m r)
657658 -> (a -> m r)
658659 -> m r
659660 -> m r
660661 )
661− -> Stream m a
662+ -> StreamK m a
662663sharedMWith cns g = mkStream $ \st yld sng stp ->
663664 g (\a r -> foldStreamShared st yld sng stp (return a `cns` r)) sng stp
664665
@@ -668,50 +669,50 @@ sharedMWith cns g = mkStream $ \st yld sng stp ->
668669
669670{-# INLINE_NORMAL augmentS #-}
670671augmentS ::
671− ((a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
672− -> Stream m a
673− -> Stream m a
672+ ((a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
673+ -> StreamK m a
674+ -> StreamK m a
674675augmentS g xs = g cons xs
675676
676677{-# 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).
678679 augmentS g nil = buildS g
679680 #-}
680681
681682{-# RULES "foldrS/augmentS"
682683 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).
684685 foldrS k z (augmentS g xs) = g k (foldrS k z xs)
685686 #-}
686687
687688{-# RULES "augmentS/buildS"
688− forall (g :: (a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
689− (h :: (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)
690+ (h :: (a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
690691 augmentS g (buildS h) = buildS (\c n -> g c (h c n))
691692 #-}
692693
693694{-# INLINE_NORMAL augmentSM #-}
694695augmentSM :: Monad m =>
695− ((m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
696− -> Stream m a -> Stream m a
696+ ((m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a)
697+ -> StreamK m a -> StreamK m a
697698augmentSM g xs = g consM xs
698699
699700{-# RULES "augmentSM/nil"
700701 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).
702703 augmentSM g nil = buildSM g
703704 #-}
704705
705706{-# RULES "foldrSM/augmentSM"
706707 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).
708709 foldrSM k z (augmentSM g xs) = g k (foldrSM k z xs)
709710 #-}
710711
711712{-# RULES "augmentSM/buildSM"
712713 forall
713− (g :: (m a -> Stream m a -> Stream m a) -> Stream m a -> Stream m a)
714− (h :: (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)
715+ (h :: (m a -> StreamK m a -> StreamK m a) -> StreamK m a -> StreamK m a).
715716 augmentSM g (buildSM h) = buildSM (\c n -> g c (h c n))
716717 #-}
717718
@@ -721,7 +722,7 @@ augmentSM g xs = g consM xs
721722
722723-- | Lazy right fold with a monadic step function.
723724{-# 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
725726foldrM step acc m = go m
726727 where
727728 go m1 =
@@ -732,15 +733,15 @@ foldrM step acc m = go m
732733
733734{-# INLINE_NORMAL foldrMKWith #-}
734735foldrMKWith
735− :: (State Stream m a
736− -> (a -> Stream m a -> m b)
736+ :: (State StreamK m a
737+ -> (a -> StreamK m a -> m b)
737738 -> (a -> m b)
738739 -> m b
739− -> Stream m a
740+ -> StreamK m a
740741 -> m b)
741742 -> (a -> m b -> m b)
742743 -> 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)
744745 -> m b
745746foldrMKWith f step acc = go
746747 where
@@ -760,7 +761,7 @@ foldrMKWith f step acc = go
760761-- XXX in which case will foldrM/buildM fusion be useful?
761762{-# RULES "foldrM/buildM"
762763 forall step acc (g :: (forall r.
763− (a -> Stream m a -> m r)
764+ (a -> StreamK m a -> m r)
764765 -> (a -> m r)
765766 -> m r
766767 -> m r
@@ -771,7 +772,7 @@ foldrMKWith f step acc = go
771772{-
772773{-# RULES "foldrM/sharedM"
773774 forall step acc (g :: (forall r.
774− (a -> Stream m a -> m r)
775+ (a -> StreamK m a -> m r)
775776 -> (a -> m r)
776777 -> m r
777778 -> m r
@@ -792,11 +793,11 @@ foldrMKWith f step acc = go
792793-- Note that the accumulator is always evaluated including the initial value.
793794{-# INLINE foldlx' #-}
794795foldlx' :: 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
796797foldlx' step begin done m = get $ go m begin
797798 where
798799 {-# NOINLINE get #-}
799− get :: Stream m x -> m b
800+ get :: StreamK m x -> m b
800801 get m1 =
801802 -- XXX we are not strictly evaluating the accumulator here. Is this
802803 -- okay?
@@ -808,7 +809,7 @@ foldlx' step begin done m = get $ go m begin
808809 -- however that is more expensive because of unnecessary recursion
809810 -- that cannot be tail call optimized. Unfolding recursion explicitly via
810811 -- continuations is much more efficient.
811− go :: Stream m a -> x -> Stream m x
812+ go :: StreamK m a -> x -> StreamK m x
812813 go m1 !acc = mkStream $ \_ yld sng _ ->
813814 let stop = sng acc
814815 single a = sng $ step acc a
@@ -819,7 +820,7 @@ foldlx' step begin done m = get $ go m begin
819820
820821-- | Strict left associative fold.
821822{-# 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
823824foldl' step begin = foldlx' step begin id
824825
825826------------------------------------------------------------------------------
@@ -836,7 +837,7 @@ foldl' step begin = foldlx' step begin id
836837-- > drain = foldl' (\_ _ -> ()) ()
837838-- > drain = mapM_ (\_ -> return ())
838839{-# INLINE drain #-}
839−drain :: Monad m => Stream m a -> m ()
840+drain :: Monad m => StreamK m a -> m ()
840841drain = foldrM (\_ xs -> xs) (return ())
841842{-
842843drain = go
@@ -849,7 +850,7 @@ drain = go
849850-}
850851
851852{-# INLINE null #-}
852−null :: Monad m => Stream m a -> m Bool
853+null :: Monad m => StreamK m a -> m Bool
853854-- null = foldrM (\_ _ -> return True) (return False)
854855null m =
855856 let stop = return True
@@ -876,7 +877,7 @@ infixr 6 `append`
876877-- 'concatMapWith' et. al.
877878--
878879{-# INLINE append #-}
879−append :: Stream m a -> Stream m a -> Stream m a
880+append :: StreamK m a -> StreamK m a -> StreamK m a
880881-- XXX This doubles the time of toNullAp benchmark, may not be fusing properly
881882-- serial xs ys = augmentS (\c n -> foldrS c n xs) ys
882883append m1 m2 = go m1
@@ -889,17 +890,17 @@ append m1 m2 = go m1
889890
890891-- join/merge/append streams depending on consM
891892{-# 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
893894conjoin xs = augmentSM (\c n -> foldrSM c n xs)
894895
895−instance Semigroup (Stream m a) where
896+instance Semigroup (StreamK m a) where
896897 (<>) = append
897898
898899------------------------------------------------------------------------------
899900-- Monoid
900901------------------------------------------------------------------------------
901902
902−instance Monoid (Stream m a) where
903+instance Monoid (StreamK m a) where
903904 mempty = nil
904905 mappend = (<>)
905906
@@ -912,11 +913,11 @@ instance Monoid (Stream m a) where
912913-- rewrite rules. Ideally don't run hlint on this file.
913914{-# INLINE_LATE mapFB #-}
914915mapFB :: forall b m a.
915− (b -> Stream m b -> Stream m b)
916+ (b -> StreamK m b -> StreamK m b)
916917 -> (a -> b)
917918 -> a
918− -> Stream m b
919− -> Stream m b
919+ -> StreamK m b
920+ -> StreamK m b
920921mapFB c f = \x ys -> c (f x) ys
921922
922923{-# RULES
@@ -925,7 +926,7 @@ mapFB c f = \x ys -> c (f x) ys
925926 #-}
926927
927928{-# INLINE map #-}
928−map :: (a -> b) -> Stream m a -> Stream m b
929+map :: (a -> b) -> StreamK m a -> StreamK m b
929930map f xs = buildS (\c n -> foldrS (mapFB c f) n xs)
930931
931932-- XXX This definition might potentially be more efficient, but the cost in the
@@ -964,15 +965,15 @@ mapMFB c f x = c (x >>= f)
964965-- XXX fusion would be easier for monomoprhic stream types.
965966-- {-# RULES "mapM serial" mapM = mapMSerial #-}
966967{-# 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
968969mapMSerial f xs = buildSM (\c n -> foldrSMShared (mapMFB c f) n xs)
969970
970971{-# INLINE mapMWith #-}
971972mapMWith ::
972− (m b -> Stream m b -> Stream m b)
973+ (m b -> StreamK m b -> StreamK m b)
973974 -> (a -> m b)
974− -> Stream m a
975− -> Stream m b
975+ -> StreamK m a
976+ -> StreamK m b
976977mapMWith cns f = foldrSShared (\x xs -> f x `cns` xs) nil
977978
978979{-
@@ -987,7 +988,7 @@ mapMWith cns f = go
987988
988989-- XXX in fact use the Stream type everywhere and only use polymorphism in the
989990-- high level modules/prelude.
990−instance Monad m => Functor (Stream m) where
991+instance Monad m => Functor (StreamK m) where
991992 fmap = map
992993
993994------------------------------------------------------------------------------
@@ -1003,8 +1004,8 @@ instance Monad m => Functor (Stream m) where
10031004-- well, because they do not get inlined. Need to add INLINE in Ord class in
10041005-- base?
10051006
1006−instance IsList (Stream Identity a) where
1007− type (Item (Stream Identity a)) = a
1007+instance IsList (StreamK Identity a) where
1008+ type (Item (StreamK Identity a)) = a
10081009
10091010 {-# INLINE fromList #-}
10101011 fromList = fromFoldable
@@ -1014,11 +1015,11 @@ instance IsList (Stream Identity a) where
10141015
10151016-- XXX Fix these
10161017{-
1017−instance Eq a => Eq (Stream Identity a) where
1018+instance Eq a => Eq (StreamK Identity a) where
10181019 {-# INLINE (==) #-}
10191020 (==) xs ys = runIdentity $ eqBy (==) xs ys
10201021
1021−instance Ord a => Ord (Stream Identity a) where
1022+instance Ord a => Ord (StreamK Identity a) where
10221023 {-# INLINE compare #-}
10231024 compare xs ys = runIdentity $ cmpBy compare xs ys
10241025
@@ -1053,18 +1054,18 @@ instance Ord a => Ord (Stream Identity a) where
10531054 min x y = if x <= y then x else y
10541055-}
10551056
1056−instance Show a => Show (Stream Identity a) where
1057+instance Show a => Show (StreamK Identity a) where
10571058 showsPrec p dl = showParen (p > 10) $
10581059 showString "fromList " . shows (toList dl)
10591060
1060−instance Read a => Read (Stream Identity a) where
1061+instance Read a => Read (StreamK Identity a) where
10611062 readPrec = parens $ prec 10 $ do
10621063 Ident "fromList" <- lexP
10631064 fromList <$> readPrec
10641065
10651066 readListPrec = readListPrecDefault
10661067
1067−instance (a ~ Char) => IsString (Stream Identity a) where
1068+instance (a ~ Char) => IsString (StreamK Identity a) where
10681069 {-# INLINE fromString #-}
10691070 fromString = fromList
10701071
@@ -1074,7 +1075,7 @@ instance (a ~ Char) => IsString (Stream Identity a) where
10741075
10751076-- | Lazy right associative fold.
10761077{-# 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
10781079foldr step acc = foldrM (\x xs -> xs >>= \b -> return (step x b)) (return acc)
10791080
10801081-- 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)
10841085-- use right folds, they cannot run in constant memory. We provide
10851086-- implementations using strict left folds here.
10861087
1087−instance (Foldable m, Monad m) => Foldable (Stream m) where
1088+instance (Foldable m, Monad m) => Foldable (StreamK m) where
10881089
10891090 {-# INLINE foldMap #-}
10901091 foldMap f =
@@ -1136,7 +1137,7 @@ instance (Foldable m, Monad m) => Foldable (Stream m) where
11361137-- Traversable
11371138-------------------------------------------------------------------------------
11381139
1139−instance Traversable (Stream Identity) where
1140+instance Traversable (StreamK Identity) where
11401141 {-# INLINE traverse #-}
11411142 traverse f xs =
11421143 runIdentity
@@ -1153,17 +1154,17 @@ instance Traversable (Stream Identity) where
11531154
11541155-- | Detach a stream from an SVar
11551156{-# INLINE unShare #-}
1156−unShare :: Stream m a -> Stream m a
1157+unShare :: StreamK m a -> StreamK m a
11571158unShare x = mkStream $ \st yld sng stp ->
11581159 foldStream st yld sng stp x
11591160
11601161-- XXX the function stream and value stream can run in parallel
11611162{-# INLINE crossApplyWith #-}
11621163crossApplyWith ::
1163− (Stream m b -> Stream m b -> Stream m b)
1164− -> Stream m (a -> b)
1165− -> Stream m a
1166− -> Stream m b
1164+ (StreamK m b -> StreamK m b -> StreamK m b)
1165+ -> StreamK m (a -> b)
1166+ -> StreamK m a
1167+ -> StreamK m b
11671168crossApplyWith par fstream stream = go1 fstream
11681169
11691170 where
@@ -1192,9 +1193,9 @@ crossApplyWith par fstream stream = go1 fstream
11921193--
11931194{-# INLINE crossApply #-}
11941195crossApply ::
1195− Stream m (a -> b)
1196− -> Stream m a
1197− -> Stream m b
1196+ StreamK m (a -> b)
1197+ -> StreamK m a
1198+ -> StreamK m b
11981199crossApply fstream stream = go1 fstream
11991200
12001201 where
@@ -1222,9 +1223,9 @@ crossApply fstream stream = go1 fstream
12221223
12231224{-# INLINE crossApplySnd #-}
12241225crossApplySnd ::
1225− Stream m a
1226− -> Stream m b
1227− -> Stream m b
1226+ StreamK m a
1227+ -> StreamK m b
1228+ -> StreamK m b
12281229crossApplySnd fstream stream = go1 fstream
12291230
12301231 where
@@ -1246,9 +1247,9 @@ crossApplySnd fstream stream = go1 fstream
12461247
12471248{-# INLINE crossApplyFst #-}
12481249crossApplyFst ::
1249− Stream m a
1250− -> Stream m b
1251− -> Stream m a
1250+ StreamK m a
1251+ -> StreamK m b
1252+ -> StreamK m a
12521253crossApplyFst fstream stream = go1 fstream
12531254
12541255 where
@@ -1282,10 +1283,10 @@ crossApplyFst fstream stream = go1 fstream
12821283-- Note that the second stream is evaluated multiple times.
12831284--
12841285{-# 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
12861287crossWith f m1 m2 = fmap f m1 `crossApply` m2
12871288
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
12891290-- combinations of the tuple @(a, b)@.
12901291--
12911292-- Definition:
@@ -1304,7 +1305,7 @@ crossWith f m1 m2 = fmap f m1 `crossApply` m2
13041305--
13051306-- /Pre-release/
13061307{-# 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)
13081309cross = crossWith (,)
13091310
13101311-- XXX This is just concatMapWith with arguments flipped. We need to keep this
@@ -1313,10 +1314,10 @@ cross = crossWith (,)
13131314-- if the argument order is changed.
13141315{-# INLINE bindWith #-}
13151316bindWith ::
1316− (Stream m b -> Stream m b -> Stream m b)
1317− -> Stream m a
1318− -> (a -> Stream m b)
1319− -> Stream m b
1317+ (StreamK m b -> StreamK m b -> StreamK m b)
1318+ -> StreamK m a
1319+ -> (a -> StreamK m b)
1320+ -> StreamK m b
13201321bindWith par m1 f = go m1
13211322 where
13221323 go m =
@@ -1341,14 +1342,14 @@ bindWith par m1 f = go m1
13411342{-# INLINE concatMapWith #-}
13421343concatMapWith
13431344 ::
1344− (Stream m b -> Stream m b -> Stream m b)
1345− -> (a -> Stream m b)
1346− -> Stream m a
1347− -> Stream m b
1345+ (StreamK m b -> StreamK m b -> StreamK m b)
1346+ -> (a -> StreamK m b)
1347+ -> StreamK m a
1348+ -> StreamK m b
13481349concatMapWith par f xs = bindWith par xs f
13491350
13501351{-# 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
13521353concatMap = concatMapWith append
13531354
13541355{-
@@ -1392,10 +1393,10 @@ concatMap_ f xs = buildS
13921393{-# INLINE mergeMapWith #-}
13931394mergeMapWith
13941395 ::
1395− (Stream m b -> Stream m b -> Stream m b)
1396− -> (a -> Stream m b)
1397− -> Stream m a
1398− -> Stream m b
1396+ (StreamK m b -> StreamK m b -> StreamK m b)
1397+ -> (a -> StreamK m b)
1398+ -> StreamK m a
1399+ -> StreamK m b
13991400mergeMapWith combine f str = go (leafPairs str)
14001401
14011402 where
@@ -1448,7 +1449,7 @@ mergeMapWith combine f str = go (leafPairs str)
14481449 in foldStream (adaptState st) yieldk single stop stream
14491450
14501451{-
1451−instance Monad m => Applicative (Stream m) where
1452+instance Monad m => Applicative (StreamK m) where
14521453 {-# INLINE pure #-}
14531454 pure = fromPure
14541455
@@ -1467,7 +1468,7 @@ instance Monad m => Applicative (Stream m) where
14671468-- NOTE: even though concatMap for StreamD is 3x faster compared to StreamK,
14681469-- the monad instance of StreamD is slower than StreamK after foldr/build
14691470-- fusion.
1470−instance Monad m => Monad (Stream m) where
1471+instance Monad m => Monad (StreamK m) where
14711472 {-# INLINE return #-}
14721473 return = pure
14731474
@@ -1506,10 +1507,10 @@ concatUnfoldr = undefined
15061507--
15071508{-# INLINE concatIterateWith #-}
15081509concatIterateWith ::
1509− (Stream m a -> Stream m a -> Stream m a)
1510− -> (a -> Stream m a)
1511− -> Stream m a
1512− -> Stream m a
1510+ (StreamK m a -> StreamK m a -> StreamK m a)
1511+ -> (a -> StreamK m a)
1512+ -> StreamK m a
1513+ -> StreamK m a
15131514concatIterateWith combine f = iterateStream
15141515
15151516 where
@@ -1532,10 +1533,10 @@ concatIterateWith combine f = iterateStream
15321533--
15331534{-# INLINE mergeIterateWith #-}
15341535mergeIterateWith ::
1535− (Stream m a -> Stream m a -> Stream m a)
1536− -> (a -> Stream m a)
1537− -> Stream m a
1538− -> Stream m a
1536+ (StreamK m a -> StreamK m a -> StreamK m a)
1537+ -> (a -> StreamK m a)
1538+ -> StreamK m a
1539+ -> StreamK m a
15391540mergeIterateWith combine f = iterateStream
15401541
15411542 where
@@ -1566,11 +1567,11 @@ mergeIterateWith combine f = iterateStream
15661567{-# INLINE concatIterateScanWith #-}
15671568concatIterateScanWith
15681569 :: Monad m
1569− => (Stream m a -> Stream m a -> Stream m a)
1570− -> (b -> a -> m (b, Stream m a))
1570+ => (StreamK m a -> StreamK m a -> StreamK m a)
1571+ -> (b -> a -> m (b, StreamK m a))
15711572 -> m b
1572− -> Stream m a
1573− -> Stream m a
1573+ -> StreamK m a
1574+ -> StreamK m a
15741575concatIterateScanWith combine f initial stream =
15751576 concatEffect $ do
15761577 b <- initial
@@ -1598,9 +1599,9 @@ concatIterateScanWith combine f initial stream =
15981599{-
15991600concatMapEitherWith
16001601 :: (forall x. t m x -> t m x -> t m x)
1601− -> (a -> t m (Either (Stream m b) b))
1602− -> Stream m a
1603− -> Stream m b
1602+ -> (a -> t m (Either (StreamK m b) b))
1603+ -> StreamK m a
1604+ -> StreamK m b
16041605concatMapEitherWith = undefined
16051606-}
16061607
@@ -1622,10 +1623,10 @@ concatMapEitherWith = undefined
16221623{-# INLINE concatIterateLeftsWith #-}
16231624concatIterateLeftsWith
16241625 :: (b ~ Either a c)
1625− => (Stream m b -> Stream m b -> Stream m b)
1626− -> (a -> Stream m b)
1627− -> Stream m b
1628− -> Stream m b
1626+ => (StreamK m b -> StreamK m b -> StreamK m b)
1627+ -> (a -> StreamK m b)
1628+ -> StreamK m b
1629+ -> StreamK m b
16291630concatIterateLeftsWith combine f =
16301631 concatIterateWith combine (either f (const nil))
16311632
@@ -1650,7 +1651,7 @@ infixr 6 `interleave`
16501651-- streams.
16511652--
16521653{-# INLINE interleave #-}
1653−interleave :: Stream m a -> Stream m a -> Stream m a
1654+interleave :: StreamK m a -> StreamK m a -> StreamK m a
16541655interleave m1 m2 = mkStream $ \st yld sng stp -> do
16551656 let stop = foldStream st yld sng stp m2
16561657 single a = yld a m2
@@ -1662,7 +1663,7 @@ infixr 6 `interleaveFst`
16621663-- | Like `interleave` but stops interleaving as soon as the first stream stops.
16631664--
16641665{-# INLINE interleaveFst #-}
1665−interleaveFst :: Stream m a -> Stream m a -> Stream m a
1666+interleaveFst :: StreamK m a -> StreamK m a -> StreamK m a
16661667interleaveFst m1 m2 = mkStream $ \st yld sng stp -> do
16671668 let yieldFirst a r = yld a (yieldSecond r m2)
16681669 in foldStream st yieldFirst sng stp m1
@@ -1681,7 +1682,7 @@ infixr 6 `interleaveMin`
16811682-- stops.
16821683--
16831684{-# INLINE interleaveMin #-}
1684−interleaveMin :: Stream m a -> Stream m a -> Stream m a
1685+interleaveMin :: StreamK m a -> StreamK m a -> StreamK m a
16851686interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
16861687 let stop = stp
16871688 -- "single a" is defined as "yld a (interleaveMin m2 nil)" instead of
@@ -1696,7 +1697,7 @@ interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
16961697-------------------------------------------------------------------------------
16971698
16981699{-# INLINE unfoldr #-}
1699−unfoldr :: (b -> Maybe (a, b)) -> b -> Stream m a
1700+unfoldr :: (b -> Maybe (a, b)) -> b -> StreamK m a
17001701unfoldr next s0 = build $ \yld stp ->
17011702 let go s =
17021703 case next s of
@@ -1706,10 +1707,10 @@ unfoldr next s0 = build $ \yld stp ->
17061707
17071708{-# INLINE unfoldrMWith #-}
17081709unfoldrMWith :: Monad m =>
1709− (m a -> Stream m a -> Stream m a)
1710+ (m a -> StreamK m a -> StreamK m a)
17101711 -> (b -> m (Maybe (a, b)))
17111712 -> b
1712− -> Stream m a
1713+ -> StreamK m a
17131714unfoldrMWith cns step = go
17141715
17151716 where
@@ -1721,14 +1722,14 @@ unfoldrMWith cns step = go
17211722 Nothing -> stp
17221723
17231724{-# 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
17251726unfoldrM = unfoldrMWith consM
17261727
17271728-- | Generate an infinite stream by repeating a pure value.
17281729--
17291730-- /Pre-release/
17301731{-# INLINE repeat #-}
1731−repeat :: a -> Stream m a
1732+repeat :: a -> StreamK m a
17321733repeat a = let x = cons a x in x
17331734
17341735-- | Like 'repeatM' but takes a stream 'cons' operation to combine the actions
@@ -1744,7 +1745,7 @@ repeatMWith cns = go
17441745 go m = m `cns` go m
17451746
17461747{-# 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
17481749replicateMWith cns n m = go n
17491750
17501751 where
@@ -1753,7 +1754,7 @@ replicateMWith cns n m = go n
17531754
17541755{-# INLINE fromIndicesMWith #-}
17551756fromIndicesMWith ::
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
17571758fromIndicesMWith cns gen = go 0
17581759
17591760 where
@@ -1763,7 +1764,7 @@ fromIndicesMWith cns gen = go 0
17631764
17641765{-# INLINE iterateMWith #-}
17651766iterateMWith :: 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
17671768iterateMWith cns step = go
17681769
17691770 where
@@ -1773,11 +1774,11 @@ iterateMWith cns step = go
17731774 foldStreamShared st stp sng yld (return next `cns` go (step next))
17741775
17751776{-# INLINE headPartial #-}
1776−headPartial :: Monad m => Stream m a -> m a
1777+headPartial :: Monad m => StreamK m a -> m a
17771778headPartial = foldrM (\x _ -> return x) (error "head of nil")
17781779
17791780{-# INLINE tailPartial #-}
1780−tailPartial :: Stream m a -> Stream m a
1781+tailPartial :: StreamK m a -> StreamK m a
17811782tailPartial m = mkStream $ \st yld sng stp ->
17821783 let stop = error "tail of nil"
17831784 single _ = stp
@@ -1835,7 +1836,7 @@ tailPartial m = mkStream $ \st yld sng stp ->
18351836--
18361837-- /Pre-release/
18371838{-# 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
18391840mfix f = mkStream $ \st yld sng stp ->
18401841 let single a = foldStream st yld sng stp $ a `cons` ys
18411842 yieldk a _ = foldStream st yld sng stp $ a `cons` ys
@@ -1862,11 +1863,11 @@ mfix f = mkStream $ \st yld sng stp ->
18621863--
18631864-- @since 0.2.0
18641865{-# INLINE fromFoldable #-}
1865−fromFoldable :: Foldable f => f a -> Stream m a
1866+fromFoldable :: Foldable f => f a -> StreamK m a
18661867fromFoldable = Prelude.foldr cons nil
18671868
18681869{-# 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
18701871fromFoldableM = Prelude.foldr consM nil
18711872
18721873-------------------------------------------------------------------------------
@@ -1874,7 +1875,7 @@ fromFoldableM = Prelude.foldr consM nil
18741875-------------------------------------------------------------------------------
18751876
18761877{-# 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))
18781879uncons m =
18791880 let stop = pure Nothing
18801881 single a = pure (Just (a, nil))
@@ -1882,7 +1883,7 @@ uncons m =
18821883 in foldStream defState yieldk single stop m
18831884
18841885{-# 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))
18861887tail =
18871888 let stop = pure Nothing
18881889 single _ = pure $ Just nil
@@ -1895,7 +1896,7 @@ tail =
18951896--
18961897-- /Pre-release/
18971898{-# 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))
18991900init = go1
19001901 where
19011902 go1 m1 = do
@@ -1914,7 +1915,7 @@ init = go1
19141915-- | Lazy left fold to a stream.
19151916{-# INLINE foldlS #-}
19161917foldlS ::
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
19181919foldlS step = go
19191920 where
19201921 go acc rest = mkStream $ \st yld sng stp ->
@@ -1925,7 +1926,7 @@ foldlS step = go
19251926 in foldStream (adaptState st) yieldk single stop rest
19261927
19271928{-# INLINE reverse #-}
1928−reverse :: Stream m a -> Stream m a
1929+reverse :: StreamK m a -> StreamK m a
19291930reverse = foldlS (flip cons) nil
19301931
19311932------------------------------------------------------------------------------
@@ -1934,20 +1935,20 @@ reverse = foldlS (flip cons) nil
19341935
19351936-- | Run an action before evaluating the stream.
19361937{-# 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
19381939before action stream =
19391940 mkStream $ \st yld sng stp ->
19401941 action >> foldStreamShared st yld sng stp stream
19411942
19421943-- | concat . fromEffect
19431944{-# INLINE concatEffect #-}
1944−concatEffect :: Monad m => m (Stream m a) -> Stream m a
1945+concatEffect :: Monad m => m (StreamK m a) -> StreamK m a
19451946concatEffect action =
19461947 mkStream $ \st yld sng stp ->
19471948 action >>= foldStreamShared st yld sng stp
19481949
19491950{-# 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
19511952concatMapEffect f action =
19521953 mkStream $ \st yld sng stp ->
19531954 action >>= foldStreamShared st yld sng stp . f
@@ -1980,7 +1981,7 @@ concatMapEffect f action =
19801981-- :}
19811982-- [(1,3),(1,4),(2,3),(2,4)]
19821983--
1983−newtype CrossStreamK m a = CrossStreamK {unCrossStreamK :: Stream m a}
1984+newtype CrossStreamK m a = CrossStreamK {unCrossStreamK :: StreamK m a}
19841985 deriving (Functor, Semigroup, Monoid, Foldable)
19851986
19861987-- | Wrap the 'StreamK' type in a 'CrossStreamK' newtype to enable cross