on master help sign in
Implement appendWithK for ordered using concatMap
8e4f8b2Harendra Kumar
src/Streamly/Internal/Data/Stream/Async/Channel.hs+13−5
@@ -132,14 +132,14 @@ evalWithD modifier m = D.Stream step Nothing
132-- appending two streams
132-- appending two streams
133-------------------------------------------------------------------------------
133-------------------------------------------------------------------------------
134
134
135−{-# INLINE appendGeneric #-}
135+{-# INLINE _appendGeneric #-}
136−appendGeneric :: MonadAsync m =>
136+_appendGeneric :: MonadAsync m =>
137 ((Config -> Config) -> m (Channel m a))
137 ((Config -> Config) -> m (Channel m a))
138 -> (Config -> Config)
138 -> (Config -> Config)
139 -> K.Stream m a
139 -> K.Stream m a
140 -> K.Stream m a
140 -> K.Stream m a
141 -> K.Stream m a
141 -> K.Stream m a
142−appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
142+_appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
143
143
144 where
144 where
145
145
@@ -164,14 +164,22 @@ appendGeneric newChan modifier stream1 stream2 = K.concatEffect action
164{-# INLINE appendWithK #-}
164{-# INLINE appendWithK #-}
165appendWithK :: MonadAsync m =>
165appendWithK :: MonadAsync m =>
166 (Config -> Config) -> K.Stream m a -> K.Stream m a -> K.Stream m a
166 (Config -> Config) -> K.Stream m a -> K.Stream m a -> K.Stream m a
167−appendWithK = appendGeneric Append.newChannel
167+appendWithK modifier stream1 stream2 =
168+{-
169+ if getOrdered (modifier defaultConfig)
170+ then concatMapWithK modifier id (stream1 `K.cons` K.fromPure stream2)
171+ else _appendGeneric Append.newChannel modifier stream1 stream2
172+-}
173+ concatMapWithK modifier id (stream1 `K.cons` K.fromPure stream2)
168
174
169-- | Create a new channel and add both the streams to it for async evaluation.
175-- | Create a new channel and add both the streams to it for async evaluation.
170-- The output stream is the result of the evaluation.
176-- The output stream is the result of the evaluation.
171{-# INLINE interleaveWithK #-}
177{-# INLINE interleaveWithK #-}
172interleaveWithK :: MonadAsync m =>
178interleaveWithK :: MonadAsync m =>
173 (Config -> Config) -> K.Stream m a -> K.Stream m a -> K.Stream m a
179 (Config -> Config) -> K.Stream m a -> K.Stream m a -> K.Stream m a
174−interleaveWithK = appendGeneric Interleave.newChannel
180+-- interleaveWithK = _appendGeneric Interleave.newChannel
181+interleaveWithK modifier stream1 stream2 =
182+ concatMapInterleaveWithK modifier id (stream1 `K.cons` K.fromPure stream2)
175
183
176-- | Evaluate the first stream in the current thread and add the second stream
184-- | Evaluate the first stream in the current thread and add the second stream
177-- to the supplied channel. This is to be used by a worker thread.
185-- to the supplied channel. This is to be used by a worker thread.