on master help sign in
Repurpose the streamk build flag
ca76876Ranjeet Kumar Ranjan
.github/workflows/haskell.yml+2−2
@@ -132,13 +132,13 @@ jobs:
132 cabal_project: cabal.project
132 cabal_project: cabal.project
133 cabal_build_options: "--flag fusion-plugin"
133 cabal_build_options: "--flag fusion-plugin"
134 ignore_error: false
134 ignore_error: false
135− - name: 8.6.5-sdist-streamk-unoptimized
135+ - name: 8.6.5-sdist-no-fusion-unoptimized
136 ghc_version: 8.6.5
136 ghc_version: 8.6.5
137 runner: ubuntu-latest
137 runner: ubuntu-latest
138 build: cabal
138 build: cabal
139 cabal_version: 3.6
139 cabal_version: 3.6
140 cabal_project: cabal.project
140 cabal_project: cabal.project
141− cabal_build_options: "--flag streamk --flag -opt"
141+ cabal_build_options: "--flag no-fusion --flag -opt"
142 ignore_error: false
142 ignore_error: false
143 - name: 8.6.5-sdist-debug-unoptimized
143 - name: 8.6.5-sdist-debug-unoptimized
144 ghc_version: 8.6.5
144 ghc_version: 8.6.5
core/src/Streamly/Internal/Data/Stream/Common.hs+6−13
@@ -33,13 +33,6 @@ where
33
33
34import Streamly.Internal.Data.Fold.Type (Fold (..))
34import Streamly.Internal.Data.Fold.Type (Fold (..))
35
35
36−#ifdef USE_STREAMK_ONLY
37−import qualified Streamly.Internal.Data.Stream.StreamK as S
38−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
39−#else
40−import qualified Streamly.Internal.Data.Stream.StreamD.Type as S
41−#endif
42−
43import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
36import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
44import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
37import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
45
38
@@ -59,15 +52,15 @@ import Prelude hiding (foldr, repeat)
59--
52--
60{-# INLINE_EARLY fromList #-}
53{-# INLINE_EARLY fromList #-}
61fromList :: Monad m => [a] -> K.Stream m a
54fromList :: Monad m => [a] -> K.Stream m a
62−fromList = S.toStreamK . S.fromList
55+fromList = D.toStreamK . D.fromList
63{-# RULES "fromList fallback to StreamK" [1]
56{-# RULES "fromList fallback to StreamK" [1]
64− forall a. S.toStreamK (S.fromList a) = K.fromFoldable a #-}
57+ forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
65
58
66-- | Convert a stream into a list in the underlying monad.
59-- | Convert a stream into a list in the underlying monad.
67--
60--
68{-# INLINE toList #-}
61{-# INLINE toList #-}
69toList :: Monad m => K.Stream m a -> m [a]
62toList :: Monad m => K.Stream m a -> m [a]
70−toList m = S.toList $ S.fromStreamK m
63+toList m = D.toList $ D.fromStreamK m
71
64
72------------------------------------------------------------------------------
65------------------------------------------------------------------------------
73-- Folds
66-- Folds
@@ -75,7 +68,7 @@ toList m = S.toList $ S.fromStreamK m
75
68
76{-# INLINE foldrM #-}
69{-# INLINE foldrM #-}
77foldrM :: Monad m => (a -> m b -> m b) -> m b -> K.Stream m a -> m b
70foldrM :: Monad m => (a -> m b -> m b) -> m b -> K.Stream m a -> m b
78−foldrM step acc m = S.foldrM step acc $ S.fromStreamK m
71+foldrM step acc m = D.foldrM step acc $ D.fromStreamK m
79
72
80{-# INLINE foldr #-}
73{-# INLINE foldr #-}
81foldr :: Monad m => (a -> b -> b) -> b -> K.Stream m a -> m b
74foldr :: Monad m => (a -> b -> b) -> b -> K.Stream m a -> m b
@@ -86,12 +79,12 @@ foldr f z = foldrM (\a b -> f a <$> b) (return z)
86{-# INLINE foldl' #-}
79{-# INLINE foldl' #-}
87foldl' ::
80foldl' ::
88 Monad m => (b -> a -> b) -> b -> K.Stream m a -> m b
81 Monad m => (b -> a -> b) -> b -> K.Stream m a -> m b
89−foldl' step begin m = S.foldl' step begin $ S.fromStreamK m
82+foldl' step begin m = D.foldl' step begin $ D.fromStreamK m
90
83
91
84
92{-# INLINE fold #-}
85{-# INLINE fold #-}
93fold :: Monad m => Fold m a b -> K.Stream m a -> m b
86fold :: Monad m => Fold m a b -> K.Stream m a -> m b
94−fold fld m = S.fold fld $ S.fromStreamK m
87+fold fld m = D.fold fld $ D.fromStreamK m
95
88
96------------------------------------------------------------------------------
89------------------------------------------------------------------------------
97-- Comparison
90-- Comparison
core/src/inline.hs+1−1
@@ -9,7 +9,7 @@
9--
9--
10-- {-# INLINE_EARLY unfoldr #-}
10-- {-# INLINE_EARLY unfoldr #-}
11-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
11-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12−-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
12+-- unfoldr step seed = fromStreamD (S.unfoldr step seed)
13-- {-# RULES "unfoldr fallback to StreamK" [1]
13-- {-# RULES "unfoldr fallback to StreamK" [1]
14-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
14-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
15--
15--
core/streamly-core.cabal−8
@@ -57,11 +57,6 @@ flag no-fusion
57 manual: True
57 manual: True
58 default: False
58 default: False
59
59
60−flag streamk
61− description: Use CPS style streams when possible
62− manual: True
63− default: False
64−
65flag use-c-malloc
60flag use-c-malloc
66 description: Use C malloc instead of GHC malloc
61 description: Use C malloc instead of GHC malloc
67 manual: True
62 manual: True
@@ -99,9 +94,6 @@ flag use-folds
99common compile-options
94common compile-options
100 default-language: Haskell2010
95 default-language: Haskell2010
101
96
102− if flag(streamk)
103− cpp-options: -DUSE_STREAMK_ONLY
104−
105 if flag(no-fusion)
97 if flag(no-fusion)
106 cpp-options: -DDISABLE_FUSION
98 cpp-options: -DDISABLE_FUSION
107
99
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+14−19
@@ -75,7 +75,7 @@ import Streamly.Internal.Data.Array.Unboxed.Type (Array)
75import Streamly.Internal.Data.Fold.Type (Fold (..))
75import Streamly.Internal.Data.Fold.Type (Fold (..))
76import Streamly.Internal.Data.Stream.IsStream.Combinators (maxYields)
76import Streamly.Internal.Data.Stream.IsStream.Combinators (maxYields)
77import Streamly.Internal.Data.Stream.IsStream.Type
77import Streamly.Internal.Data.Stream.IsStream.Type
78− (IsStream(..), fromStreamD, toStreamD, fromStreamS, toStreamS)
78+ (IsStream(..), fromStreamD, toStreamD)
79import Streamly.Internal.Data.Stream.Serial (SerialT)
79import Streamly.Internal.Data.Stream.Serial (SerialT)
80import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
80import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
81import Streamly.Internal.System.IO (defaultChunkSize)
81import Streamly.Internal.System.IO (defaultChunkSize)
@@ -87,11 +87,6 @@ import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
87import qualified Streamly.Internal.Data.Stream.Parallel as Par
87import qualified Streamly.Internal.Data.Stream.Parallel as Par
88import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
88import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
89import qualified Streamly.Internal.Data.Stream.StreamD as D
89import qualified Streamly.Internal.Data.Stream.StreamD as D
90−#ifdef USE_STREAMK_ONLY
91−import qualified Streamly.Internal.Data.Stream.StreamK as S
92−#else
93−import qualified Streamly.Internal.Data.Stream.StreamD as S
94−#endif
95import qualified Streamly.Internal.Data.Stream as Stream
90import qualified Streamly.Internal.Data.Stream as Stream
96
91
97import Prelude hiding (take, takeWhile, drop, reverse, concatMap, map, zipWith)
92import Prelude hiding (take, takeWhile, drop, reverse, concatMap, map, zipWith)
@@ -202,7 +197,7 @@ repeatM = K.repeatMWith IsStream.consM
202{-# RULES "repeatM serial" repeatM = repeatMSerial #-}
197{-# RULES "repeatM serial" repeatM = repeatMSerial #-}
203{-# INLINE repeatMSerial #-}
198{-# INLINE repeatMSerial #-}
204repeatMSerial :: MonadAsync m => m a -> SerialT m a
199repeatMSerial :: MonadAsync m => m a -> SerialT m a
205−repeatMSerial = fromStreamS . S.repeatM
200+repeatMSerial = fromStreamD . D.repeatM
206
201
207------------------------------------------------------------------------------
202------------------------------------------------------------------------------
208-- Generation - Time related
203-- Generation - Time related
@@ -298,7 +293,7 @@ foldContinue f s = D.foldContinue f $ IsStream.toStreamD s
298-- Same as 'fmap'.
293-- Same as 'fmap'.
299--
294--
300-- @
295-- @
301−-- > S.toList $ S.map (+1) $ S.fromList [1,2,3]
296+-- > D.toList $ D.map (+1) $ D.fromList [1,2,3]
302-- [2,3,4]
297-- [2,3,4]
303-- @
298-- @
304--
299--
@@ -397,7 +392,7 @@ smapM step initial stream =
397-- @since 0.1.0
392-- @since 0.1.0
398{-# INLINE take #-}
393{-# INLINE take #-}
399take :: (IsStream t, Monad m) => Int -> t m a -> t m a
394take :: (IsStream t, Monad m) => Int -> t m a -> t m a
400−take n m = fromStreamS $ S.take n $ toStreamS
395+take n m = fromStreamD $ D.take n $ toStreamD
401 (maxYields (Just (fromIntegral n)) m)
396 (maxYields (Just (fromIntegral n)) m)
402
397
403-- | End the stream as soon as the predicate fails on an element.
398-- | End the stream as soon as the predicate fails on an element.
@@ -405,7 +400,7 @@ take n m = fromStreamS $ S.take n $ toStreamS
405-- @since 0.1.0
400-- @since 0.1.0
406{-# INLINE takeWhile #-}
401{-# INLINE takeWhile #-}
407takeWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
402takeWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
408−takeWhile p m = fromStreamS $ S.takeWhile p $ toStreamS m
403+takeWhile p m = fromStreamD $ D.takeWhile p $ toStreamD m
409
404
410{-# INLINE takeEndBy #-}
405{-# INLINE takeEndBy #-}
411takeEndBy :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
406takeEndBy :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
@@ -416,7 +411,7 @@ takeEndBy p m = fromStreamD $ D.takeEndBy p $ toStreamD m
416-- @since 0.1.0
411-- @since 0.1.0
417{-# INLINE drop #-}
412{-# INLINE drop #-}
418drop :: (IsStream t, Monad m) => Int -> t m a -> t m a
413drop :: (IsStream t, Monad m) => Int -> t m a -> t m a
419−drop n m = fromStreamS $ S.drop n $ toStreamS m
414+drop n m = fromStreamD $ D.drop n $ toStreamD m
420
415
421------------------------------------------------------------------------------
416------------------------------------------------------------------------------
422-- Searching
417-- Searching
@@ -430,7 +425,7 @@ drop n m = fromStreamS $ S.drop n $ toStreamS m
430-- @since 0.5.0
425-- @since 0.5.0
431{-# INLINE findIndices #-}
426{-# INLINE findIndices #-}
432findIndices :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m Int
427findIndices :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m Int
433−findIndices p m = fromStreamS $ S.findIndices p (toStreamS m)
428+findIndices p m = fromStreamD $ D.findIndices p (toStreamD m)
434
429
435------------------------------------------------------------------------------
430------------------------------------------------------------------------------
436-- Transformation by Inserting
431-- Transformation by Inserting
@@ -454,7 +449,7 @@ findIndices p m = fromStreamS $ S.findIndices p (toStreamS m)
454-- @since 0.5.0
449-- @since 0.5.0
455{-# INLINE intersperseM #-}
450{-# INLINE intersperseM #-}
456intersperseM :: (IsStream t, MonadAsync m) => m a -> t m a -> t m a
451intersperseM :: (IsStream t, MonadAsync m) => m a -> t m a -> t m a
457−intersperseM m = fromStreamS . S.intersperseM m . toStreamS
452+intersperseM m = fromStreamD . D.intersperseM m . toStreamD
458
453
459-- | Intersperse a monadic action into the input stream after every @n@
454-- | Intersperse a monadic action into the input stream after every @n@
460-- seconds.
455-- seconds.
@@ -493,7 +488,7 @@ interjectSuffix n f xs = xs `parallelFst` repeatM timed
493-- /Since: 0.1.1/
488-- /Since: 0.1.1/
494{-# INLINE reverse #-}
489{-# INLINE reverse #-}
495reverse :: (IsStream t, Monad m) => t m a -> t m a
490reverse :: (IsStream t, Monad m) => t m a -> t m a
496−reverse s = fromStreamS $ S.reverse $ toStreamS s
491+reverse s = fromStreamD $ D.reverse $ toStreamD s
497
492
498-- | Like 'reverse' but several times faster, requires a 'Storable' instance.
493-- | Like 'reverse' but several times faster, requires a 'Storable' instance.
499--
494--
@@ -699,8 +694,8 @@ splitOnSeq patt f m =
699{-# INLINE zipWithM #-}
694{-# INLINE zipWithM #-}
700zipWithM :: (IsStream t, Monad m) => (a -> b -> m c) -> t m a -> t m b -> t m c
695zipWithM :: (IsStream t, Monad m) => (a -> b -> m c) -> t m a -> t m b -> t m c
701zipWithM f m1 m2 =
696zipWithM f m1 m2 =
702− IsStream.fromStreamS
697+ IsStream.fromStreamD
703− $ S.zipWithM f (IsStream.toStreamS m1) (IsStream.toStreamS m2)
698+ $ D.zipWithM f (IsStream.toStreamD m1) (IsStream.toStreamD m2)
704
699
705-- | Stream @a@ is evaluated first, followed by stream @b@, the resulting
700-- | Stream @a@ is evaluated first, followed by stream @b@, the resulting
706-- elements @a@ and @b@ are then zipped using the supplied zip function and the
701-- elements @a@ and @b@ are then zipped using the supplied zip function and the
@@ -710,7 +705,7 @@ zipWithM f m1 m2 =
710-- first, the element @a@ from previous evaluation of stream @a@ is discarded.
705-- first, the element @a@ from previous evaluation of stream @a@ is discarded.
711--
706--
712-- @
707-- @
713−-- > S.toList $ S.zipWith (+) (S.fromList [1,2,3]) (S.fromList [4,5,6])
708+-- > D.toList $ D.zipWith (+) (D.fromList [1,2,3]) (D.fromList [4,5,6])
714-- [5,7,9]
709-- [5,7,9]
715-- @
710-- @
716--
711--
@@ -718,5 +713,5 @@ zipWithM f m1 m2 =
718{-# INLINE zipWith #-}
713{-# INLINE zipWith #-}
719zipWith :: (IsStream t, Monad m) => (a -> b -> c) -> t m a -> t m b -> t m c
714zipWith :: (IsStream t, Monad m) => (a -> b -> c) -> t m a -> t m b -> t m c
720zipWith f m1 m2 =
715zipWith f m1 m2 =
721− IsStream.fromStreamS
716+ IsStream.fromStreamD
722− $ S.zipWith f (IsStream.toStreamS m1) (IsStream.toStreamS m2)
717+ $ D.zipWith f (IsStream.toStreamD m1) (IsStream.toStreamD m2)
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+23−28
@@ -163,7 +163,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
163 ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
163 ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
164 , take , takeWhile, mkParallel)
164 , take , takeWhile, mkParallel)
165import Streamly.Internal.Data.Stream.IsStream.Type
165import Streamly.Internal.Data.Stream.IsStream.Type
166− (IsStream, toStreamS, fromStreamD, toStreamD)
166+ (IsStream, toStreamD, fromStreamD, toStreamD)
167import Streamly.Internal.Data.Stream.Serial (SerialT)
167import Streamly.Internal.Data.Stream.Serial (SerialT)
168import Streamly.Internal.Data.Unboxed (Unboxed)
168import Streamly.Internal.Data.Unboxed (Unboxed)
169
169
@@ -172,11 +172,6 @@ import qualified Streamly.Internal.Data.Fold as FL
172import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
172import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
173import qualified Streamly.Internal.Data.Stream.StreamD as D
173import qualified Streamly.Internal.Data.Stream.StreamD as D
174import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
174import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
175−#ifdef USE_STREAMK_ONLY
176−import qualified Streamly.Internal.Data.Stream.StreamK as S
177−#else
178−import qualified Streamly.Internal.Data.Stream.StreamD as S
179−#endif
180import qualified Streamly.Internal.Data.Stream as Stream
175import qualified Streamly.Internal.Data.Stream as Stream
181import qualified System.IO as IO
176import qualified System.IO as IO
182
177
@@ -240,7 +235,7 @@ uncons = fmap (fmap (fmap IsStream.fromStream)) . K.uncons . Stream.toStreamK
240{-# INLINE foldr1 #-}
235{-# INLINE foldr1 #-}
241{-# DEPRECATED foldr1 "Use foldrM instead." #-}
236{-# DEPRECATED foldr1 "Use foldrM instead." #-}
242foldr1 :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
237foldr1 :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
243−foldr1 f m = S.foldr1 f (toStreamS m)
238+foldr1 f m = D.foldr1 f (toStreamD m)
244
239
245------------------------------------------------------------------------------
240------------------------------------------------------------------------------
246-- Left Folds
241-- Left Folds
@@ -260,12 +255,12 @@ foldlS f z =
260--
255--
261-- For example, to reverse a stream:
256-- For example, to reverse a stream:
262--
257--
263−-- > S.toList $ S.foldlT (flip S.cons) S.nil $ (S.fromList [1..5] :: SerialT IO Int)
258+-- > D.toList $ D.foldlT (flip D.cons) D.nil $ (D.fromList [1..5] :: SerialT IO Int)
264--
259--
265{-# INLINE foldlT #-}
260{-# INLINE foldlT #-}
266foldlT :: (Monad m, IsStream t, Monad (s m), MonadTrans s)
261foldlT :: (Monad m, IsStream t, Monad (s m), MonadTrans s)
267 => (s m b -> a -> s m b) -> s m b -> t m a -> s m b
262 => (s m b -> a -> s m b) -> s m b -> t m a -> s m b
268−foldlT f z s = S.foldlT f z (toStreamS s)
263+foldlT f z s = D.foldlT f z (toStreamD s)
269
264
270-- | Strict left fold with an extraction function. Like the standard strict
265-- | Strict left fold with an extraction function. Like the standard strict
271-- left fold, but applies a user supplied extraction function (the third
266-- left fold, but applies a user supplied extraction function (the third
@@ -320,7 +315,7 @@ foldxM = IsStream.foldlMx'
320-- /Since: 0.8.0 (signature change)/
315-- /Since: 0.8.0 (signature change)/
321{-# INLINE foldlM' #-}
316{-# INLINE foldlM' #-}
322foldlM' :: Monad m => (b -> a -> m b) -> m b -> SerialT m a -> m b
317foldlM' :: Monad m => (b -> a -> m b) -> m b -> SerialT m a -> m b
323−foldlM' step begin = S.foldlM' step begin . IsStream.toStreamS
318+foldlM' step begin = D.foldlM' step begin . IsStream.toStreamD
324
319
325------------------------------------------------------------------------------
320------------------------------------------------------------------------------
326-- Running a sink
321-- Running a sink
@@ -347,7 +342,7 @@ runSink = fold . toFold
347-- @since 0.1.0
342-- @since 0.1.0
348{-# INLINE mapM_ #-}
343{-# INLINE mapM_ #-}
349mapM_ :: Monad m => (a -> m b) -> SerialT m a -> m ()
344mapM_ :: Monad m => (a -> m b) -> SerialT m a -> m ()
350−mapM_ f = S.mapM_ f . IsStream.toStreamS
345+mapM_ f = D.mapM_ f . IsStream.toStreamD
351
346
352-- |
347-- |
353-- > drain = mapM_ (\_ -> return ())
348-- > drain = mapM_ (\_ -> return ())
@@ -422,7 +417,7 @@ runStream = drain
422-- @since 0.1.1
417-- @since 0.1.1
423{-# INLINE null #-}
418{-# INLINE null #-}
424null :: Monad m => SerialT m a -> m Bool
419null :: Monad m => SerialT m a -> m Bool
425−null = S.null . toStreamS
420+null = D.null . toStreamD
426
421
427-- | Extract the first element of the stream, if any.
422-- | Extract the first element of the stream, if any.
428--
423--
@@ -432,7 +427,7 @@ null = S.null . toStreamS
432-- @since 0.1.0
427-- @since 0.1.0
433{-# INLINE head #-}
428{-# INLINE head #-}
434head :: Monad m => SerialT m a -> m (Maybe a)
429head :: Monad m => SerialT m a -> m (Maybe a)
435−head = S.head . toStreamS
430+head = D.head . toStreamD
436
431
437-- | Extract the first element of the stream, if any, otherwise use the
432-- | Extract the first element of the stream, if any, otherwise use the
438-- supplied default value. It can help avoid one branch in high performance
433-- supplied default value. It can help avoid one branch in high performance
@@ -468,7 +463,7 @@ init m = fmap (fmap IsStream.fromStream) $ K.init $ Stream.toStreamK m
468-- @since 0.1.1
463-- @since 0.1.1
469{-# INLINE last #-}
464{-# INLINE last #-}
470last :: Monad m => SerialT m a -> m (Maybe a)
465last :: Monad m => SerialT m a -> m (Maybe a)
471−last m = S.last $ toStreamS m
466+last m = D.last $ toStreamD m
472
467
473-- | Determine whether an element is present in the stream.
468-- | Determine whether an element is present in the stream.
474--
469--
@@ -477,7 +472,7 @@ last m = S.last $ toStreamS m
477-- @since 0.1.0
472-- @since 0.1.0
478{-# INLINE elem #-}
473{-# INLINE elem #-}
479elem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
474elem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
480−elem e m = S.elem e (toStreamS m)
475+elem e m = D.elem e (toStreamD m)
481
476
482-- | Determine whether an element is not present in the stream.
477-- | Determine whether an element is not present in the stream.
483--
478--
@@ -486,7 +481,7 @@ elem e m = S.elem e (toStreamS m)
486-- @since 0.1.0
481-- @since 0.1.0
487{-# INLINE notElem #-}
482{-# INLINE notElem #-}
488notElem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
483notElem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
489−notElem e m = S.notElem e (toStreamS m)
484+notElem e m = D.notElem e (toStreamD m)
490
485
491-- | Determine the length of the stream.
486-- | Determine the length of the stream.
492--
487--
@@ -502,7 +497,7 @@ length = foldl' (\n _ -> n + 1) 0
502-- @since 0.1.0
497-- @since 0.1.0
503{-# INLINE all #-}
498{-# INLINE all #-}
504all :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
499all :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
505−all p m = S.all p (toStreamS m)
500+all p m = D.all p (toStreamD m)
506
501
507-- | Determine whether any of the elements of a stream satisfy a predicate.
502-- | Determine whether any of the elements of a stream satisfy a predicate.
508--
503--
@@ -511,7 +506,7 @@ all p m = S.all p (toStreamS m)
511-- @since 0.1.0
506-- @since 0.1.0
512{-# INLINE any #-}
507{-# INLINE any #-}
513any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
508any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
514−any p m = S.any p (toStreamS m)
509+any p m = D.any p (toStreamD m)
515
510
516-- | Determines if all elements of a boolean stream are True.
511-- | Determines if all elements of a boolean stream are True.
517--
512--
@@ -572,7 +567,7 @@ mconcat = Stream.foldr mappend mempty
572-- @since 0.1.0
567-- @since 0.1.0
573{-# INLINE minimum #-}
568{-# INLINE minimum #-}
574minimum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
569minimum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
575−minimum m = S.minimum (toStreamS m)
570+minimum m = D.minimum (toStreamD m)
576
571
577-- | Determine the minimum element in a stream using the supplied comparison
572-- | Determine the minimum element in a stream using the supplied comparison
578-- function.
573-- function.
@@ -582,7 +577,7 @@ minimum m = S.minimum (toStreamS m)
582-- @since 0.6.0
577-- @since 0.6.0
583{-# INLINE minimumBy #-}
578{-# INLINE minimumBy #-}
584minimumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
579minimumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
585−minimumBy cmp m = S.minimumBy cmp (toStreamS m)
580+minimumBy cmp m = D.minimumBy cmp (toStreamD m)
586
581
587-- |
582-- |
588-- @
583-- @
@@ -595,7 +590,7 @@ minimumBy cmp m = S.minimumBy cmp (toStreamS m)
595-- @since 0.1.0
590-- @since 0.1.0
596{-# INLINE maximum #-}
591{-# INLINE maximum #-}
597maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
592maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
598−maximum m = S.maximum (toStreamS m)
593+maximum m = D.maximum (toStreamD m)
599
594
600-- | Determine the maximum element in a stream using the supplied comparison
595-- | Determine the maximum element in a stream using the supplied comparison
601-- function.
596-- function.
@@ -605,7 +600,7 @@ maximum m = S.maximum (toStreamS m)
605-- @since 0.6.0
600-- @since 0.6.0
606{-# INLINE maximumBy #-}
601{-# INLINE maximumBy #-}
607maximumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
602maximumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
608−maximumBy cmp m = S.maximumBy cmp (toStreamS m)
603+maximumBy cmp m = D.maximumBy cmp (toStreamD m)
609
604
610-- | Ensures that all the elements of the stream are identical and then returns
605-- | Ensures that all the elements of the stream are identical and then returns
611-- that unique element.
606-- that unique element.
@@ -613,7 +608,7 @@ maximumBy cmp m = S.maximumBy cmp (toStreamS m)
613-- @since 0.6.0
608-- @since 0.6.0
614{-# INLINE the #-}
609{-# INLINE the #-}
615the :: (Eq a, Monad m) => SerialT m a -> m (Maybe a)
610the :: (Eq a, Monad m) => SerialT m a -> m (Maybe a)
616−the m = S.the (toStreamS m)
611+the m = D.the (toStreamD m)
617
612
618------------------------------------------------------------------------------
613------------------------------------------------------------------------------
619-- Searching
614-- Searching
@@ -624,7 +619,7 @@ the m = S.the (toStreamS m)
624-- @since 0.6.0
619-- @since 0.6.0
625{-# INLINE (!!) #-}
620{-# INLINE (!!) #-}
626(!!) :: Monad m => SerialT m a -> Int -> m (Maybe a)
621(!!) :: Monad m => SerialT m a -> Int -> m (Maybe a)
627−m !! i = toStreamS m S.!! i
622+m !! i = toStreamD m D.!! i
628
623
629-- | In a stream of (key-value) pairs @(a, b)@, return the value @b@ of the
624-- | In a stream of (key-value) pairs @(a, b)@, return the value @b@ of the
630-- first pair where the key equals the given value @a@.
625-- first pair where the key equals the given value @a@.
@@ -635,7 +630,7 @@ m !! i = toStreamS m S.!! i
635-- @since 0.5.0
630-- @since 0.5.0
636{-# INLINE lookup #-}
631{-# INLINE lookup #-}
637lookup :: (Monad m, Eq a) => a -> SerialT m (a, b) -> m (Maybe b)
632lookup :: (Monad m, Eq a) => a -> SerialT m (a, b) -> m (Maybe b)
638−lookup a m = S.lookup a (toStreamS m)
633+lookup a m = D.lookup a (toStreamD m)
639
634
640-- | Like 'findM' but with a non-monadic predicate.
635-- | Like 'findM' but with a non-monadic predicate.
641--
636--
@@ -645,7 +640,7 @@ lookup a m = S.lookup a (toStreamS m)
645-- @since 0.5.0
640-- @since 0.5.0
646{-# INLINE find #-}
641{-# INLINE find #-}
647find :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe a)
642find :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe a)
648−find p m = S.find p (toStreamS m)
643+find p m = D.find p (toStreamD m)
649
644
650-- | Returns the first element that satisfies the given predicate.
645-- | Returns the first element that satisfies the given predicate.
651--
646--
@@ -654,7 +649,7 @@ find p m = S.find p (toStreamS m)
654-- @since 0.6.0
649-- @since 0.6.0
655{-# INLINE findM #-}
650{-# INLINE findM #-}
656findM :: Monad m => (a -> m Bool) -> SerialT m a -> m (Maybe a)
651findM :: Monad m => (a -> m Bool) -> SerialT m a -> m (Maybe a)
657−findM p m = S.findM p (toStreamS m)
652+findM p m = D.findM p (toStreamD m)
658
653
659-- | Returns the first index that satisfies the given predicate.
654-- | Returns the first index that satisfies the given predicate.
660--
655--
@@ -712,7 +707,7 @@ toListRev = D.toListRev . toStreamD
712
707
713-- |
708-- |
714-- @
709-- @
715−-- toHandle h = S.mapM_ $ hPutStrLn h
710+-- toHandle h = D.mapM_ $ hPutStrLn h
716-- @
711-- @
717--
712--
718-- Write a stream of Strings to an IO Handle.
713-- Write a stream of Strings to an IO Handle.
src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+1−1
@@ -763,7 +763,7 @@ mergeMinBy _f _m1 _m2 = undefined
763mergeFstBy :: -- (IsStream t, Monad m) =>
763mergeFstBy :: -- (IsStream t, Monad m) =>
764 (a -> a -> m Ordering) -> t m a -> t m a -> t m a
764 (a -> a -> m Ordering) -> t m a -> t m a -> t m a
765mergeFstBy _f _m1 _m2 = undefined
765mergeFstBy _f _m1 _m2 = undefined
766− -- fromStreamS $ D.mergeFstBy f (toStreamD m1) (toStreamD m2)
766+ -- fromStreamD $ D.mergeFstBy f (toStreamD m1) (toStreamD m2)
767
767
768-- XXX we may want to use the name "merge" differently
768-- XXX we may want to use the name "merge" differently
769-- | Same as @'mergeBy' 'compare'@.
769-- | Same as @'mergeBy' 'compare'@.
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+10−16
@@ -99,7 +99,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
99 ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, fromEffect
99 ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, fromEffect
100 , yield, yieldM, repeatM)
100 , yield, yieldM, repeatM)
101import Streamly.Internal.Data.Stream.IsStream.Type
101import Streamly.Internal.Data.Stream.IsStream.Type
102− (IsStream (..), fromSerial, consM, fromStreamD, fromStreamS)
102+ (IsStream (..), fromSerial, consM, fromStreamD)
103import Streamly.Internal.Data.Stream.Serial (SerialT)
103import Streamly.Internal.Data.Stream.Serial (SerialT)
104import Streamly.Internal.Data.Stream.WSerial (WSerialT)
104import Streamly.Internal.Data.Stream.WSerial (WSerialT)
105import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
105import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
@@ -112,12 +112,6 @@ import qualified Streamly.Internal.Data.Stream.Parallel as Par
112import qualified Streamly.Internal.Data.Stream.Serial as Serial
112import qualified Streamly.Internal.Data.Stream.Serial as Serial
113import qualified Streamly.Internal.Data.Stream.StreamD.Generate as D
113import qualified Streamly.Internal.Data.Stream.StreamD.Generate as D
114import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
114import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
115−#ifdef USE_STREAMK_ONLY
116−import qualified Streamly.Internal.Data.Stream.StreamK as S
117−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
118−#else
119−import qualified Streamly.Internal.Data.Stream.StreamD.Generate as S
120−#endif
121import qualified Streamly.Internal.Data.Stream.Type as Stream
115import qualified Streamly.Internal.Data.Stream.Type as Stream
122import qualified System.IO as IO
116import qualified System.IO as IO
123
117
@@ -187,9 +181,9 @@ unfold0 unf = unfold unf (error "unfold0: unexpected void evaluation")
187-- @since 0.1.0
181-- @since 0.1.0
188{-# INLINE_EARLY unfoldr #-}
182{-# INLINE_EARLY unfoldr #-}
189unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
183unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
190−unfoldr step seed = fromStreamS (S.unfoldr step seed)
184+unfoldr step seed = fromStreamD (D.unfoldr step seed)
191{-# RULES "unfoldr fallback to StreamK" [1]
185{-# RULES "unfoldr fallback to StreamK" [1]
192− forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}
186+ forall a b. D.toStreamK (D.unfoldr a b) = K.unfoldr a b #-}
193
187
194-- | Build a stream by unfolding a /monadic/ step function starting from a
188-- | Build a stream by unfolding a /monadic/ step function starting from a
195-- seed. The step function returns the next element in the stream and the next
189-- seed. The step function returns the next element in the stream and the next
@@ -253,7 +247,7 @@ unfoldrMZipSerial f = fromSerial . Serial.unfoldrM f
253-- @since 0.4.0
247-- @since 0.4.0
254{-# INLINE_NORMAL repeat #-}
248{-# INLINE_NORMAL repeat #-}
255repeat :: (IsStream t, Monad m) => a -> t m a
249repeat :: (IsStream t, Monad m) => a -> t m a
256−repeat = fromStreamS . S.repeat
250+repeat = fromStreamD . D.repeat
257
251
258-- |
252-- |
259-- >>> replicate n = Stream.take n . Stream.repeat
253-- >>> replicate n = Stream.take n . Stream.repeat
@@ -263,7 +257,7 @@ repeat = fromStreamS . S.repeat
263-- @since 0.6.0
257-- @since 0.6.0
264{-# INLINE_NORMAL replicate #-}
258{-# INLINE_NORMAL replicate #-}
265replicate :: (IsStream t, Monad m) => Int -> a -> t m a
259replicate :: (IsStream t, Monad m) => Int -> a -> t m a
266−replicate n = fromStreamS . S.replicate n
260+replicate n = fromStreamD . D.replicate n
267
261
268-- |
262-- |
269-- >>> replicateM n = Stream.take n . Stream.repeatM
263-- >>> replicateM n = Stream.take n . Stream.repeatM
@@ -297,7 +291,7 @@ replicateM count =
297{-# RULES "replicateM serial" replicateM = replicateMSerial #-}
291{-# RULES "replicateM serial" replicateM = replicateMSerial #-}
298{-# INLINE replicateMSerial #-}
292{-# INLINE replicateMSerial #-}
299replicateMSerial :: MonadAsync m => Int -> m a -> SerialT m a
293replicateMSerial :: MonadAsync m => Int -> m a -> SerialT m a
300−replicateMSerial n = fromStreamS . S.replicateM n
294+replicateMSerial n = fromStreamD . D.replicateM n
301
295
302------------------------------------------------------------------------------
296------------------------------------------------------------------------------
303-- Time Enumeration
297-- Time Enumeration
@@ -420,7 +414,7 @@ timeout = undefined
420-- @since 0.6.0
414-- @since 0.6.0
421{-# INLINE fromIndices #-}
415{-# INLINE fromIndices #-}
422fromIndices :: (IsStream t, Monad m) => (Int -> a) -> t m a
416fromIndices :: (IsStream t, Monad m) => (Int -> a) -> t m a
423−fromIndices = fromStreamS . S.fromIndices
417+fromIndices = fromStreamD . D.fromIndices
424
418
425--
419--
426-- |
420-- |
@@ -441,7 +435,7 @@ fromIndicesM = fromStream . K.fromIndicesMWith (IsStream.toConsK (consM @t))
441{-# RULES "fromIndicesM serial" fromIndicesM = fromIndicesMSerial #-}
435{-# RULES "fromIndicesM serial" fromIndicesM = fromIndicesMSerial #-}
442{-# INLINE fromIndicesMSerial #-}
436{-# INLINE fromIndicesMSerial #-}
443fromIndicesMSerial :: MonadAsync m => (Int -> m a) -> SerialT m a
437fromIndicesMSerial :: MonadAsync m => (Int -> m a) -> SerialT m a
444−fromIndicesMSerial = fromStreamS . S.fromIndicesM
438+fromIndicesMSerial = fromStreamD . D.fromIndicesM
445
439
446------------------------------------------------------------------------------
440------------------------------------------------------------------------------
447-- Iterating functions
441-- Iterating functions
@@ -460,7 +454,7 @@ fromIndicesMSerial = fromStreamS . S.fromIndicesM
460-- @since 0.1.2
454-- @since 0.1.2
461{-# INLINE_NORMAL iterate #-}
455{-# INLINE_NORMAL iterate #-}
462iterate :: (IsStream t, Monad m) => (a -> a) -> a -> t m a
456iterate :: (IsStream t, Monad m) => (a -> a) -> a -> t m a
463−iterate step = fromStreamS . S.iterate step
457+iterate step = fromStreamD . D.iterate step
464
458
465-- |
459-- |
466-- >>> iterateM f m = m >>= \a -> return a `Stream.consM` iterateM f (f a)
460-- >>> iterateM f m = m >>= \a -> return a `Stream.consM` iterateM f (f a)
@@ -509,7 +503,7 @@ iterateM f = fromStream . K.iterateMWith (IsStream.toConsK (consM @t)) f
509{-# RULES "iterateM serial" iterateM = iterateMSerial #-}
503{-# RULES "iterateM serial" iterateM = iterateMSerial #-}
510{-# INLINE iterateMSerial #-}
504{-# INLINE iterateMSerial #-}
511iterateMSerial :: MonadAsync m => (a -> m a) -> m a -> SerialT m a
505iterateMSerial :: MonadAsync m => (a -> m a) -> m a -> SerialT m a
512−iterateMSerial step = fromStreamS . S.iterateM step
506+iterateMSerial step = fromStreamD . D.iterateM step
513
507
514-- | We can define cyclic structures using @let@:
508-- | We can define cyclic structures using @let@:
515--
509--
src/Streamly/Internal/Data/Stream/IsStream/Lift.hs+3−8
@@ -29,15 +29,10 @@ import Control.Monad.Trans.State.Strict (StateT)
29import Control.Monad.Trans.Class (MonadTrans(..))
29import Control.Monad.Trans.Class (MonadTrans(..))
30import Data.Functor.Identity (Identity (..))
30import Data.Functor.Identity (Identity (..))
31import Streamly.Internal.Data.Stream.IsStream.Type
31import Streamly.Internal.Data.Stream.IsStream.Type
32− (IsStream(..), fromStreamS, toStreamS, fromStreamD, toStreamD)
32+ (IsStream(..), fromStreamD, toStreamD)
33import Streamly.Internal.Data.Stream.Serial (SerialT)
33import Streamly.Internal.Data.Stream.Serial (SerialT)
34
34
35import qualified Streamly.Internal.Data.Stream.StreamD as D
35import qualified Streamly.Internal.Data.Stream.StreamD as D
36−#ifdef USE_STREAMK_ONLY
37−import qualified Streamly.Internal.Data.Stream.StreamK as S
38−#else
39−import qualified Streamly.Internal.Data.Stream.StreamD as S
40−#endif
41
36
42------------------------------------------------------------------------------
37------------------------------------------------------------------------------
43-- Generalize the underlying monad
38-- Generalize the underlying monad
@@ -50,7 +45,7 @@ import qualified Streamly.Internal.Data.Stream.StreamD as S
50{-# INLINE hoist #-}
45{-# INLINE hoist #-}
51hoist :: (Monad m, Monad n)
46hoist :: (Monad m, Monad n)
52 => (forall x. m x -> n x) -> SerialT m a -> SerialT n a
47 => (forall x. m x -> n x) -> SerialT m a -> SerialT n a
53−hoist f xs = fromStreamS $ S.hoist f (toStreamS xs)
48+hoist f xs = fromStreamD $ D.hoist f (toStreamD xs)
54
49
55-- | Generalize the inner monad of the stream from 'Identity' to any monad.
50-- | Generalize the inner monad of the stream from 'Identity' to any monad.
56--
51--
@@ -58,7 +53,7 @@ hoist f xs = fromStreamS $ S.hoist f (toStreamS xs)
58--
53--
59{-# INLINE generally #-}
54{-# INLINE generally #-}
60generally :: (IsStream t, Monad m) => t Identity a -> t m a
55generally :: (IsStream t, Monad m) => t Identity a -> t m a
61−generally xs = fromStreamS $ S.hoist (return . runIdentity) (toStreamS xs)
56+generally xs = fromStreamD $ D.hoist (return . runIdentity) (toStreamD xs)
62
57
63------------------------------------------------------------------------------
58------------------------------------------------------------------------------
64-- Add and remove a monad transformer
59-- Add and remove a monad transformer
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+10−15
@@ -247,7 +247,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
247 )
247 )
248import Streamly.Internal.Control.Concurrent (MonadAsync)
248import Streamly.Internal.Control.Concurrent (MonadAsync)
249import Streamly.Internal.Data.Stream.IsStream.Type
249import Streamly.Internal.Data.Stream.IsStream.Type
250− (IsStream(..), fromStreamS, toStreamS, fromStreamD, toStreamD, toConsK)
250+ (IsStream(..), fromStreamD, toStreamD, toConsK)
251import Streamly.Internal.Data.Stream.Serial (SerialT)
251import Streamly.Internal.Data.Stream.Serial (SerialT)
252import Streamly.Internal.Data.SVar (Rate(..))
252import Streamly.Internal.Data.SVar (Rate(..))
253import Streamly.Internal.Data.Time.Units (TimeUnit64, AbsTime, RelTime64)
253import Streamly.Internal.Data.Time.Units (TimeUnit64, AbsTime, RelTime64)
@@ -257,11 +257,6 @@ import qualified Streamly.Internal.Data.Stream.Parallel as Par
257import qualified Streamly.Internal.Data.Stream.Serial as Serial
257import qualified Streamly.Internal.Data.Stream.Serial as Serial
258import qualified Streamly.Internal.Data.Stream.StreamD as D
258import qualified Streamly.Internal.Data.Stream.StreamD as D
259import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
259import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
260−#ifdef USE_STREAMK_ONLY
261−import qualified Streamly.Internal.Data.Stream.StreamK as S
262−#else
263−import qualified Streamly.Internal.Data.Stream.StreamD as S
264−#endif
265import qualified Prelude
260import qualified Prelude
266
261
267import Prelude hiding
262import Prelude hiding
@@ -359,7 +354,7 @@ foldrSShared f z xs =
359{-# INLINE foldrT #-}
354{-# INLINE foldrT #-}
360foldrT :: (IsStream t, Monad m, Monad (s m), MonadTrans s)
355foldrT :: (IsStream t, Monad m, Monad (s m), MonadTrans s)
361 => (a -> s m b -> s m b) -> s m b -> t m a -> s m b
356 => (a -> s m b -> s m b) -> s m b -> t m a -> s m b
362−foldrT f z s = S.foldrT f z (toStreamS s)
357+foldrT f z s = D.foldrT f z (toStreamD s)
363
358
364------------------------------------------------------------------------------
359------------------------------------------------------------------------------
365-- Transformation by Mapping
360-- Transformation by Mapping
@@ -681,7 +676,7 @@ postscan fld = fromStreamD . D.postscanOnce fld . toStreamD
681{-# DEPRECATED scanx "Please use scanl followed by map instead." #-}
676{-# DEPRECATED scanx "Please use scanl followed by map instead." #-}
682{-# INLINE scanx #-}
677{-# INLINE scanx #-}
683scanx :: (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
678scanx :: (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
684−scanx step begin done = fromStreamS . S.scanlx' step begin done . toStreamS
679+scanx step begin done = fromStreamD . D.scanlx' step begin done . toStreamD
685
680
686-- XXX this needs to be concurrent
681-- XXX this needs to be concurrent
687-- XXX because of the use of D.cons for appending, scanlM' has quadratic
682-- XXX because of the use of D.cons for appending, scanlM' has quadratic
@@ -760,7 +755,7 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
760-- @since 0.2.0
755-- @since 0.2.0
761{-# INLINE scanl' #-}
756{-# INLINE scanl' #-}
762scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
757scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
763−scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
758+scanl' step z m = fromStreamD $ D.scanl' step z $ toStreamD m
764
759
765-- | Like 'scanl'' but does not stream the initial value of the accumulator.
760-- | Like 'scanl'' but does not stream the initial value of the accumulator.
766--
761--
@@ -841,7 +836,7 @@ with f comb g = fmap snd . comb g . f
841-- @since 0.1.0
836-- @since 0.1.0
842{-# INLINE filter #-}
837{-# INLINE filter #-}
843filter :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
838filter :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
844−filter p m = fromStreamS $ S.filter p $ toStreamS m
839+filter p m = fromStreamD $ D.filter p $ toStreamD m
845
840
846-- | Same as 'filter' but with a monadic predicate.
841-- | Same as 'filter' but with a monadic predicate.
847--
842--
@@ -953,7 +948,7 @@ nubBy = undefined -- fromStreamD . D.nubBy . toStreamD
953-- @since 0.6.0
948-- @since 0.6.0
954{-# INLINE deleteBy #-}
949{-# INLINE deleteBy #-}
955deleteBy :: (IsStream t, Monad m) => (a -> a -> Bool) -> a -> t m a -> t m a
950deleteBy :: (IsStream t, Monad m) => (a -> a -> Bool) -> a -> t m a -> t m a
956−deleteBy cmp x m = fromStreamS $ S.deleteBy cmp x (toStreamS m)
951+deleteBy cmp x m = fromStreamD $ D.deleteBy cmp x (toStreamD m)
957
952
958------------------------------------------------------------------------------
953------------------------------------------------------------------------------
959-- Lossy Buffering
954-- Lossy Buffering
@@ -1082,7 +1077,7 @@ takeInterval d = fromStreamD . D.takeByTime d . toStreamD
1082-- @since 0.1.0
1077-- @since 0.1.0
1083{-# INLINE dropWhile #-}
1078{-# INLINE dropWhile #-}
1084dropWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
1079dropWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
1085−dropWhile p m = fromStreamS $ S.dropWhile p $ toStreamS m
1080+dropWhile p m = fromStreamD $ D.dropWhile p $ toStreamD m
1086
1081
1087-- | Same as 'dropWhile' but with a monadic predicate.
1082-- | Same as 'dropWhile' but with a monadic predicate.
1088--
1083--
@@ -1171,7 +1166,7 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
1171{-# INLINE insertBy #-}
1166{-# INLINE insertBy #-}
1172insertBy ::
1167insertBy ::
1173 (IsStream t, Monad m) => (a -> a -> Ordering) -> a -> t m a -> t m a
1168 (IsStream t, Monad m) => (a -> a -> Ordering) -> a -> t m a -> t m a
1174−insertBy cmp x m = fromStreamS $ S.insertBy cmp x (toStreamS m)
1169+insertBy cmp x m = fromStreamD $ D.insertBy cmp x (toStreamD m)
1175
1170
1176-- | Insert a pure value between successive elements of a stream.
1171-- | Insert a pure value between successive elements of a stream.
1177--
1172--
@@ -1181,7 +1176,7 @@ insertBy cmp x m = fromStreamS $ S.insertBy cmp x (toStreamS m)
1181-- @since 0.7.0
1176-- @since 0.7.0
1182{-# INLINE intersperse #-}
1177{-# INLINE intersperse #-}
1183intersperse :: (IsStream t, MonadAsync m) => a -> t m a -> t m a
1178intersperse :: (IsStream t, MonadAsync m) => a -> t m a -> t m a
1184−intersperse a = fromStreamS . S.intersperse a . toStreamS
1179+intersperse a = fromStreamD . D.intersperse a . toStreamD
1185
1180
1186-- | Insert a side effect before consuming an element of a stream except the
1181-- | Insert a side effect before consuming an element of a stream except the
1187-- first one.
1182-- first one.
@@ -1503,7 +1498,7 @@ rollingMap2 f m = fromStreamD $ D.rollingMap2 f $ toStreamD m
1503-- @since 0.3.0
1498-- @since 0.3.0
1504{-# INLINE mapMaybe #-}
1499{-# INLINE mapMaybe #-}
1505mapMaybe :: (IsStream t, Monad m) => (a -> Maybe b) -> t m a -> t m b
1500mapMaybe :: (IsStream t, Monad m) => (a -> Maybe b) -> t m a -> t m b
1506−mapMaybe f m = fromStreamS $ S.mapMaybe f $ toStreamS m
1501+mapMaybe f m = fromStreamD $ D.mapMaybe f $ toStreamD m
1507
1502
1508-- | Like 'mapMaybe' but maps a monadic function.
1503-- | Like 'mapMaybe' but maps a monadic function.
1509--
1504--
src/Streamly/Internal/Data/Stream/IsStream/Type.hs+11−28
@@ -17,8 +17,6 @@ module Streamly.Internal.Data.Stream.IsStream.Type
17 , K.Stream (..)
17 , K.Stream (..)
18
18
19 -- * Type Conversion
19 -- * Type Conversion
20− , fromStreamS
21− , toStreamS
22 , fromStreamD
20 , fromStreamD
23 , toStreamD
21 , toStreamD
24 , adapt
22 , adapt
@@ -121,12 +119,6 @@ import qualified Streamly.Internal.Data.Stream.Serial as Serial
121import qualified Streamly.Internal.Data.Stream.WSerial as WSerial
119import qualified Streamly.Internal.Data.Stream.WSerial as WSerial
122import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
120import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
123import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
121import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
124−#ifdef USE_STREAMK_ONLY
125−import qualified Streamly.Internal.Data.Stream.StreamK as S
126−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
127−#else
128−import qualified Streamly.Internal.Data.Stream.StreamD.Type as S
129−#endif
130import qualified Streamly.Internal.Data.Stream.Type as Stream
122import qualified Streamly.Internal.Data.Stream.Type as Stream
131import qualified Streamly.Internal.Data.Stream.Zip as Zip
123import qualified Streamly.Internal.Data.Stream.Zip as Zip
132import qualified Streamly.Internal.Data.Stream.ZipAsync as ZipAsync
124import qualified Streamly.Internal.Data.Stream.ZipAsync as ZipAsync
@@ -230,15 +222,6 @@ toConsK cns x xs = toStream $ x `cns` fromStream xs
230-- Conversion to and from direct style stream
222-- Conversion to and from direct style stream
231------------------------------------------------------------------------------
223------------------------------------------------------------------------------
232
224
233−-- These definitions are dependent on what is imported as S
234−{-# INLINE fromStreamS #-}
235−fromStreamS :: (IsStream t, Monad m) => S.Stream m a -> t m a
236−fromStreamS = fromStream . S.toStreamK
237−
238−{-# INLINE toStreamS #-}
239−toStreamS :: (IsStream t, Monad m) => t m a -> S.Stream m a
240−toStreamS = S.fromStreamK . toStream
241−
242{-# INLINE toStreamD #-}
225{-# INLINE toStreamD #-}
243toStreamD :: (IsStream t, Monad m) => t m a -> D.Stream m a
226toStreamD :: (IsStream t, Monad m) => t m a -> D.Stream m a
244toStreamD = D.fromStreamK . toStream
227toStreamD = D.fromStreamK . toStream
@@ -289,16 +272,16 @@ cmpBy f m1 m2 = D.cmpBy f (toStreamD m1) (toStreamD m2)
289-- @since 0.4.0
272-- @since 0.4.0
290{-# INLINE_EARLY fromList #-}
273{-# INLINE_EARLY fromList #-}
291fromList :: (Monad m, IsStream t) => [a] -> t m a
274fromList :: (Monad m, IsStream t) => [a] -> t m a
292−fromList = fromStreamS . S.fromList
275+fromList = fromStreamD . D.fromList
293{-# RULES "fromList fallback to StreamK" [1]
276{-# RULES "fromList fallback to StreamK" [1]
294− forall a. S.toStreamK (S.fromList a) = K.fromFoldable a #-}
277+ forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
295
278
296-- | Convert a stream into a list in the underlying monad.
279-- | Convert a stream into a list in the underlying monad.
297--
280--
298-- @since 0.1.0
281-- @since 0.1.0
299{-# INLINE toList #-}
282{-# INLINE toList #-}
300toList :: (IsStream t, Monad m) => t m a -> m [a]
283toList :: (IsStream t, Monad m) => t m a -> m [a]
301−toList m = S.toList $ toStreamS m
284+toList m = D.toList $ toStreamD m
302
285
303------------------------------------------------------------------------------
286------------------------------------------------------------------------------
304-- Building a stream
287-- Building a stream
@@ -364,7 +347,7 @@ foldrMx step final project m = D.foldrMx step final project $ toStreamD m
364foldlMx' ::
347foldlMx' ::
365 (IsStream t, Monad m)
348 (IsStream t, Monad m)
366 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
349 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
367−foldlMx' step begin done m = S.foldlMx' step begin done $ toStreamS m
350+foldlMx' step begin done m = D.foldlMx' step begin done $ toStreamD m
368
351
369-- | Strict left fold with an extraction function. Like the standard strict
352-- | Strict left fold with an extraction function. Like the standard strict
370-- left fold, but applies a user supplied extraction function (the third
353-- left fold, but applies a user supplied extraction function (the third
@@ -375,7 +358,7 @@ foldlMx' step begin done m = S.foldlMx' step begin done $ toStreamS m
375{-# INLINE foldlx' #-}
358{-# INLINE foldlx' #-}
376foldlx' ::
359foldlx' ::
377 (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
360 (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
378−foldlx' step begin done m = S.foldlx' step begin done $ toStreamS m
361+foldlx' step begin done m = D.foldlx' step begin done $ toStreamD m
379
362
380-- | Strict left associative fold.
363-- | Strict left associative fold.
381--
364--
@@ -383,12 +366,12 @@ foldlx' step begin done m = S.foldlx' step begin done $ toStreamS m
383{-# INLINE foldl' #-}
366{-# INLINE foldl' #-}
384foldl' ::
367foldl' ::
385 (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
368 (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
386−foldl' step begin m = S.foldl' step begin $ toStreamS m
369+foldl' step begin m = D.foldl' step begin $ toStreamD m
387
370
388
371
389{-# INLINE fold #-}
372{-# INLINE fold #-}
390fold :: (IsStream t, Monad m) => Fold m a b -> t m a -> m b
373fold :: (IsStream t, Monad m) => Fold m a b -> t m a -> m b
391−fold fld m = S.fold fld $ toStreamS m
374+fold fld m = D.fold fld $ toStreamD m
392
375
393------------------------------------------------------------------------------
376------------------------------------------------------------------------------
394-- Folding a stream
377-- Folding a stream
@@ -746,8 +729,8 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) nil
746-- Equivalent to:
729-- Equivalent to:
747--
730--
748-- @
731-- @
749−-- concatForFoldableWith f xs g = Prelude.foldr (f . g) S.nil xs
732+-- concatForFoldableWith f xs g = Prelude.foldr (f . g) D.nil xs
750−-- concatForFoldableWith f = flip (S.concatMapFoldableWith f)
733+-- concatForFoldableWith f = flip (D.concatMapFoldableWith f)
751-- @
734-- @
752--
735--
753-- /Since: 0.8.0 (Renamed forEachWith to concatForFoldableWith)/
736-- /Since: 0.8.0 (Renamed forEachWith to concatForFoldableWith)/
@@ -766,8 +749,8 @@ concatForFoldableWith f = flip (concatMapFoldableWith f)
766-- Equivalent to:
749-- Equivalent to:
767--
750--
768-- @
751-- @
769−-- concatFoldableWith f = Prelude.foldr f S.nil
752+-- concatFoldableWith f = Prelude.foldr f D.nil
770−-- concatFoldableWith f = S.concatMapFoldableWith f id
753+-- concatFoldableWith f = D.concatMapFoldableWith f id
771-- @
754-- @
772--
755--
773-- /Since: 0.8.0 (Renamed foldWith to concatFoldableWith)/
756-- /Since: 0.8.0 (Renamed foldWith to concatFoldableWith)/
src/inline.hs+1−1
@@ -9,7 +9,7 @@
9--
9--
10-- {-# INLINE_EARLY unfoldr #-}
10-- {-# INLINE_EARLY unfoldr #-}
11-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
11-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12−-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
12+-- unfoldr step seed = fromStreamD (S.unfoldr step seed)
13-- {-# RULES "unfoldr fallback to StreamK" [1]
13-- {-# RULES "unfoldr fallback to StreamK" [1]
14-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
14-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
15--
15--
streamly.cabal−8
@@ -285,11 +285,6 @@ flag has-llvm
285 manual: True
285 manual: True
286 default: False
286 default: False
287
287
288−flag streamk
289− description: Use CPS style streams when possible
290− manual: True
291− default: False
292−
293flag use-c-malloc
288flag use-c-malloc
294 description: Use C malloc instead of GHC malloc
289 description: Use C malloc instead of GHC malloc
295 manual: True
290 manual: True
@@ -321,9 +316,6 @@ common compile-options
321 if os(windows)
316 if os(windows)
322 cpp-options: -DCABAL_OS_WINDOWS
317 cpp-options: -DCABAL_OS_WINDOWS
323
318
324− if flag(streamk)
325− cpp-options: -DUSE_STREAMK_ONLY
326−
327 if flag(dev)
319 if flag(dev)
328 cpp-options: -DDEVBUILD
320 cpp-options: -DDEVBUILD
329
321