on master help sign in
Add @since annotations, bump version, update changelog
7ad55f8Harendra Kumar
.travis.yml+2−2
@@ -91,8 +91,8 @@ matrix:
91 #- env: BUILD=cabal CABALVER=2.0 GHCVER=8.2.2
91 #- env: BUILD=cabal CABALVER=2.0 GHCVER=8.2.2
92 # addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.2], sources: [hvr-ghc]}}
92 # addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.2], sources: [hvr-ghc]}}
93
93
94− - env: BUILD=cabal CABALVER=2.2 GHCVER=8.4.1
94+ - env: BUILD=cabal CABALVER=2.2 GHCVER=8.4.2
95− addons: {apt: {packages: [cabal-install-2.2,ghc-8.4.1], sources: [hvr-ghc]}}
95+ addons: {apt: {packages: [cabal-install-2.2,ghc-8.4.2], sources: [hvr-ghc]}}
96
96
97 - env: BUILD=cabal CABALVER=head GHCVER=head
97 - env: BUILD=cabal CABALVER=head GHCVER=head
98 addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}}
98 addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}}
Changelog.md+4−5
@@ -1,4 +1,4 @@
1−## Unreleased
1+## 0.2.0
2
2
3### Breaking changes
3### Breaking changes
4* Change the semantics of the Semigroup instance for `InterleavedT`, `AsyncT`
4* Change the semantics of the Semigroup instance for `InterleavedT`, `AsyncT`
@@ -12,10 +12,8 @@
12 To adapt to the new changes, replace `<>` with `splice` wherever it is used
12 To adapt to the new changes, replace `<>` with `splice` wherever it is used
13 for stream types other than `StreamT`.
13 for stream types other than `StreamT`.
14
14
15−* Change the semantics of `Alternative` instance. The `<|>` operator now has a
16− different behavior for each type. See the documentation for more details. To
17− adapt to this change replace any usage of `<|>` with `parallel` and
15+* Remove the `Alternative` instance. To adapt to this change replace any usage
18− `empty` with `nil`.
16+ of `<|>` with `parallel` and `empty` with `nil`.
19* Stream type now defaults to the `StreamT` type unless explicitly specified
17* Stream type now defaults to the `StreamT` type unless explicitly specified
20 using a type combinator or a monomorphic type. This change reduces puzzling
18 using a type combinator or a monomorphic type. This change reduces puzzling
21 type errors for beginners. It includes the following two changes:
19 type errors for beginners. It includes the following two changes:
@@ -38,6 +36,7 @@
38
36
39### Deprecations
37### Deprecations
40* Deprecate and rename the following symbols:
38* Deprecate and rename the following symbols:
39+ * `MonadAsync` to `MonadParallel`
41 * `Streaming` to `IsStream`
40 * `Streaming` to `IsStream`
42 * `runStreaming` to `runStream`
41 * `runStreaming` to `runStream`
43 * `AsyncT` to `CoparallelT`
42 * `AsyncT` to `CoparallelT`
README.md+15−6
@@ -8,13 +8,13 @@
8
8
9## Stream`ing` `Concurrent`ly
9## Stream`ing` `Concurrent`ly
10
10
11−Streamly, short for stream concurrently, is a simple yet powerful streaming
11+Streamly, short for streaming concurrently, is a simple yet powerful streaming
12library with concurrent merging and concurrent nested looping support. A stream
12library with concurrent merging and concurrent nested looping support. A stream
13is just like a list except that it is a list of monadic actions rather than
13is just like a list except that it is a list of monadic actions rather than
14pure values. Streamly streams can be generated, consumed, combined, or
14pure values. Streamly streams can be generated, consumed, combined, or
15transformed serially or concurrently. We can loop over a stream serially or
15transformed serially or concurrently. We can loop over a stream serially or
16concurrently. We can also have serial or concurrent nesting of loops. For
16concurrently. We can also have serial or concurrent nesting of loops. For
17−those familiar with the list transformer concept this is a concurrent list
17+those familiar with the list transformer concept streamly is a concurrent list
18transformer. Streamly uses standard composition abstractions. Concurrent
18transformer. Streamly uses standard composition abstractions. Concurrent
19composition is just the same as serial composition except that we use a simple
19composition is just the same as serial composition except that we use a simple
20combinator to request a concurrent composition instead of serial. The
20combinator to request a concurrent composition instead of serial. The
@@ -37,10 +37,19 @@ and supports concurrency we can write FRP applications similar in concept to
37[Yampa](https://hackage.haskell.org/package/Yampa) or
37[Yampa](https://hackage.haskell.org/package/Yampa) or
38[reflex](https://hackage.haskell.org/package/reflex).
38[reflex](https://hackage.haskell.org/package/reflex).
39
39
40−Streamly has excellent performance, see
40+Why use streamly?
41+
42+ * Simple list like streaming API, if you know how to use lists then you know
43+ how to use streamly.
44+ * Powerful yet simple and scalable concurrency. There is no other package
45+ that provides such high level and flexible concurrency support.
46+ * Unifies the functionality of many other disparate packages in a single
47+ concise and simple API.
48+ * Best in class performance. See
41−[streaming-benchmarks](https://github.com/composewell/streaming-benchmarks)
49+ [streaming-benchmarks](https://github.com/composewell/streaming-benchmarks)
42−for a comparison of popular streaming libraries on micro-benchmarks. For
50+ for a comparison of popular streaming libraries on micro-benchmarks.
51+
43−more information:
52+ For more information:
44
53
45 * [Streamly.Tutorial](https://hackage.haskell.org/package/streamly-0.1.2/docs/Streamly-Tutorial.html) module in the haddock documentation for a detailed introduction
54 * [Streamly.Tutorial](https://hackage.haskell.org/package/streamly-0.1.2/docs/Streamly-Tutorial.html) module in the haddock documentation for a detailed introduction
46 * [examples](https://github.com/composewell/streamly/tree/master/examples) directory in the package for some simple practical examples
55 * [examples](https://github.com/composewell/streamly/tree/master/examples) directory in the package for some simple practical examples
src/Streamly.hs+1
@@ -129,6 +129,7 @@ module Streamly
129 , InterleavedT
129 , InterleavedT
130 , AsyncT
130 , AsyncT
131 , ZipAsync
131 , ZipAsync
132+ , serially
132 , interleaving
133 , interleaving
133 , asyncly
134 , asyncly
134 , zipping
135 , zipping
src/Streamly/Core.hs+4
@@ -243,8 +243,12 @@ cosplice m1 m2 = Stream $ \_ stp sng yld -> do
243-- | A monad that can perform concurrent or parallel IO operations. Streams
243-- | A monad that can perform concurrent or parallel IO operations. Streams
244-- that can be composed concurrently require the underlying monad to be
244-- that can be composed concurrently require the underlying monad to be
245-- 'MonadParallel'.
245-- 'MonadParallel'.
246+--
247+-- @since 0.2.0
246type MonadParallel m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
248type MonadParallel m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
247
249
250+-- |
251+-- @since 0.1.0
248{-# DEPRECATED MonadAsync "Please use MonadParallel instead." #-}
252{-# DEPRECATED MonadAsync "Please use MonadParallel instead." #-}
249type MonadAsync m = MonadParallel m
253type MonadAsync m = MonadParallel m
250
254
src/Streamly/Prelude.hs+104
@@ -145,6 +145,8 @@ import Streamly.Streams
145------------------------------------------------------------------------------
145------------------------------------------------------------------------------
146
146
147-- | Build a Stream by unfolding pure steps starting from a seed.
147-- | Build a Stream by unfolding pure steps starting from a seed.
148+--
149+-- @since 0.1.0
148unfoldr :: IsStream t => (b -> Maybe (a, b)) -> b -> t m a
150unfoldr :: IsStream t => (b -> Maybe (a, b)) -> b -> t m a
149unfoldr step = fromStream . go
151unfoldr step = fromStream . go
150 where
152 where
@@ -154,6 +156,8 @@ unfoldr step = fromStream . go
154 Just (a, b) -> yld a (go b)
156 Just (a, b) -> yld a (go b)
155
157
156-- | Build a Stream by unfolding monadic steps starting from a seed.
158-- | Build a Stream by unfolding monadic steps starting from a seed.
159+--
160+-- @since 0.1.0
157unfoldrM :: (IsStream t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
161unfoldrM :: (IsStream t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
158unfoldrM step = fromStream . go
162unfoldrM step = fromStream . go
159 where
163 where
@@ -164,11 +168,15 @@ unfoldrM step = fromStream . go
164 Just (a, b) -> yld a (go b)
168 Just (a, b) -> yld a (go b)
165
169
166-- | Construct a stream from a 'Foldable' container.
170-- | Construct a stream from a 'Foldable' container.
171+--
172+-- @since 0.2.0
167{-# INLINE fromFoldable #-}
173{-# INLINE fromFoldable #-}
168fromFoldable :: (IsStream t, Foldable f) => f a -> t m a
174fromFoldable :: (IsStream t, Foldable f) => f a -> t m a
169fromFoldable = Prelude.foldr cons nil
175fromFoldable = Prelude.foldr cons nil
170
176
171-- | Same as 'fromFoldable'.
177-- | Same as 'fromFoldable'.
178+--
179+-- @since 0.1.0
172{-# DEPRECATED each "Please use fromFoldable instead." #-}
180{-# DEPRECATED each "Please use fromFoldable instead." #-}
173{-# INLINE each #-}
181{-# INLINE each #-}
174each :: (IsStream t, Foldable f) => f a -> t m a
182each :: (IsStream t, Foldable f) => f a -> t m a
@@ -182,10 +190,14 @@ each = fromFoldable
182-- hello
190-- hello
183-- ["hello"]
191-- ["hello"]
184-- @
192-- @
193+--
194+-- @since 0.2.0
185once :: (IsStream t, Monad m) => m a -> t m a
195once :: (IsStream t, Monad m) => m a -> t m a
186once = fromStream . S.once
196once = fromStream . S.once
187
197
188-- | Generate a stream by performing a monadic action @n@ times.
198-- | Generate a stream by performing a monadic action @n@ times.
199+--
200+-- @since 0.1.1
189replicateM :: (IsStream t, Monad m) => Int -> m a -> t m a
201replicateM :: (IsStream t, Monad m) => Int -> m a -> t m a
190replicateM n m = fromStream $ go n
202replicateM n m = fromStream $ go n
191 where
203 where
@@ -195,6 +207,8 @@ replicateM n m = fromStream $ go n
195 else m >>= \a -> yld a (go (cnt - 1))
207 else m >>= \a -> yld a (go (cnt - 1))
196
208
197-- | Generate a stream by repeatedly executing a monadic action forever.
209-- | Generate a stream by repeatedly executing a monadic action forever.
210+--
211+-- @since 0.2.0
198repeatM :: (IsStream t, Monad m) => m a -> t m a
212repeatM :: (IsStream t, Monad m) => m a -> t m a
199repeatM = fromStream . go
213repeatM = fromStream . go
200 where
214 where
@@ -202,6 +216,8 @@ repeatM = fromStream . go
202 m >>= \a -> yld a (go m)
216 m >>= \a -> yld a (go m)
203
217
204-- | Iterate a pure function from a seed value, streaming the results forever.
218-- | Iterate a pure function from a seed value, streaming the results forever.
219+--
220+-- @since 0.1.2
205iterate :: IsStream t => (a -> a) -> a -> t m a
221iterate :: IsStream t => (a -> a) -> a -> t m a
206iterate step = fromStream . go
222iterate step = fromStream . go
207 where
223 where
@@ -209,6 +225,8 @@ iterate step = fromStream . go
209
225
210-- | Iterate a monadic function from a seed value, streaming the results
226-- | Iterate a monadic function from a seed value, streaming the results
211-- forever.
227-- forever.
228+--
229+-- @since 0.1.2
212iterateM :: (IsStream t, Monad m) => (a -> m a) -> a -> t m a
230iterateM :: (IsStream t, Monad m) => (a -> m a) -> a -> t m a
213iterateM step = fromStream . go
231iterateM step = fromStream . go
214 where
232 where
@@ -217,6 +235,8 @@ iterateM step = fromStream . go
217 yld s (go a)
235 yld s (go a)
218
236
219-- | Read lines from an IO Handle into a stream of Strings.
237-- | Read lines from an IO Handle into a stream of Strings.
238+--
239+-- @since 0.1.0
220fromHandle :: (IsStream t, MonadIO m) => IO.Handle -> t m String
240fromHandle :: (IsStream t, MonadIO m) => IO.Handle -> t m String
221fromHandle h = fromStream go
241fromHandle h = fromStream go
222 where
242 where
@@ -238,6 +258,8 @@ fromHandle h = fromStream go
238-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
258-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
239-- [1,2,3]
259-- [1,2,3]
240-- @
260-- @
261+--
262+-- @since 0.1.0
241foldr :: Monad m => (a -> b -> b) -> b -> StreamT m a -> m b
263foldr :: Monad m => (a -> b -> b) -> b -> StreamT m a -> m b
242foldr step acc m = go (toStream m)
264foldr step acc m = go (toStream m)
243 where
265 where
@@ -254,6 +276,8 @@ foldr step acc m = go (toStream m)
254-- >> runIdentity $ foldrM (\\x xs -> return (x : xs)) [] (serially $ fromFoldable [1,2,3])
276-- >> runIdentity $ foldrM (\\x xs -> return (x : xs)) [] (serially $ fromFoldable [1,2,3])
255-- [1,2,3]
277-- [1,2,3]
256-- @
278-- @
279+--
280+-- @since 0.2.0
257{-# INLINE foldrM #-}
281{-# INLINE foldrM #-}
258foldrM :: Monad m => (a -> b -> m b) -> b -> StreamT m a -> m b
282foldrM :: Monad m => (a -> b -> m b) -> b -> StreamT m a -> m b
259foldrM step acc m = go (toStream m)
283foldrM step acc m = go (toStream m)
@@ -268,6 +292,8 @@ foldrM step acc m = go (toStream m)
268-- user supplied extraction function (the third argument) at each step. This is
292-- user supplied extraction function (the third argument) at each step. This is
269-- designed to work with the @foldl@ library. The suffix @x@ is a mnemonic for
293-- designed to work with the @foldl@ library. The suffix @x@ is a mnemonic for
270-- extraction.
294-- extraction.
295+--
296+-- @since 0.2.0
271{-# INLINE scanx #-}
297{-# INLINE scanx #-}
272scanx :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
298scanx :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
273scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
299scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
@@ -279,6 +305,8 @@ scanx step begin done m = cons (done begin) $ fromStream $ go (toStream m) begin
279 in yld (done s) (go r s)
305 in yld (done s) (go r s)
280 in S.runStream m1 Nothing stp single yield
306 in S.runStream m1 Nothing stp single yield
281
307
308+-- |
309+-- @since 0.1.1
282{-# DEPRECATED scan "Please use scanx instead." #-}
310{-# DEPRECATED scan "Please use scanx instead." #-}
283scan :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
311scan :: IsStream t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
284scan = scanx
312scan = scanx
@@ -287,6 +315,8 @@ scan = scanx
287-- step, generating a stream of all intermediate fold results. The first
315-- step, generating a stream of all intermediate fold results. The first
288-- element of the stream is the user supplied initial value, and the last
316-- element of the stream is the user supplied initial value, and the last
289-- element of the stream is the same as the result of 'foldl''.
317-- element of the stream is the same as the result of 'foldl''.
318+--
319+-- @since 0.2.0
290{-# INLINE scanl' #-}
320{-# INLINE scanl' #-}
291scanl' :: IsStream t => (b -> a -> b) -> b -> t m a -> t m b
321scanl' :: IsStream t => (b -> a -> b) -> b -> t m a -> t m b
292scanl' step begin m = scanx step begin id m
322scanl' step begin m = scanx step begin id m
@@ -295,6 +325,8 @@ scanl' step begin m = scanx step begin id m
295-- left fold, but applies a user supplied extraction function (the third
325-- left fold, but applies a user supplied extraction function (the third
296-- argument) to the folded value at the end. This is designed to work with the
326-- argument) to the folded value at the end. This is designed to work with the
297-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
327-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
328+--
329+-- @since 0.2.0
298{-# INLINE foldx #-}
330{-# INLINE foldx #-}
299foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
331foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
300foldx step begin done m = get $ go (toStream m) begin
332foldx step begin done m = get $ go (toStream m) begin
@@ -316,17 +348,23 @@ foldx step begin done m = get $ go (toStream m) begin
316 in (S.runStream stream) Nothing undefined sng yld
348 in (S.runStream stream) Nothing undefined sng yld
317 in (S.runStream m1) Nothing stop single yield
349 in (S.runStream m1) Nothing stop single yield
318
350
351+-- |
352+-- @since 0.1.0
319{-# DEPRECATED foldl "Please use foldx instead." #-}
353{-# DEPRECATED foldl "Please use foldx instead." #-}
320foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
354foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
321foldl = foldx
355foldl = foldx
322
356
323-- | Strict left associative fold.
357-- | Strict left associative fold.
358+--
359+-- @since 0.2.0
324{-# INLINE foldl' #-}
360{-# INLINE foldl' #-}
325foldl' :: Monad m => (b -> a -> b) -> b -> StreamT m a -> m b
361foldl' :: Monad m => (b -> a -> b) -> b -> StreamT m a -> m b
326foldl' step begin m = foldx step begin id m
362foldl' step begin m = foldx step begin id m
327
363
328-- XXX replace the recursive "go" with explicit continuations.
364-- XXX replace the recursive "go" with explicit continuations.
329-- | Like 'foldx', but with a monadic step function.
365-- | Like 'foldx', but with a monadic step function.
366+--
367+-- @since 0.2.0
330foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
368foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
331foldxM step begin done m = go begin (toStream m)
369foldxM step begin done m = go begin (toStream m)
332 where
370 where
@@ -336,17 +374,23 @@ foldxM step begin done m = go begin (toStream m)
336 yield a r = acc >>= \b -> go (step b a) r
374 yield a r = acc >>= \b -> go (step b a) r
337 in (S.runStream m1) Nothing stop single yield
375 in (S.runStream m1) Nothing stop single yield
338
376
377+-- |
378+-- @since 0.1.0
339{-# DEPRECATED foldlM "Please use foldxM instead." #-}
379{-# DEPRECATED foldlM "Please use foldxM instead." #-}
340foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
380foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
341foldlM = foldxM
381foldlM = foldxM
342
382
343-- | Like 'foldl'' but with a monadic step function.
383-- | Like 'foldl'' but with a monadic step function.
384+--
385+-- @since 0.2.0
344foldlM' :: Monad m => (b -> a -> m b) -> b -> StreamT m a -> m b
386foldlM' :: Monad m => (b -> a -> m b) -> b -> StreamT m a -> m b
345foldlM' step begin m = foldxM step (return begin) return m
387foldlM' step begin m = foldxM step (return begin) return m
346
388
347-- | Decompose a stream into its head and tail. If the stream is empty, returns
389-- | Decompose a stream into its head and tail. If the stream is empty, returns
348-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
390-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
349-- the head of the stream and 'ma' its tail.
391-- the head of the stream and 'ma' its tail.
392+--
393+-- @since 0.1.0
350uncons :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (a, t m a))
394uncons :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (a, t m a))
351uncons m =
395uncons m =
352 let stop = return Nothing
396 let stop = return Nothing
@@ -355,6 +399,8 @@ uncons m =
355 in (S.runStream (toStream m)) Nothing stop single yield
399 in (S.runStream (toStream m)) Nothing stop single yield
356
400
357-- | Write a stream of Strings to an IO Handle.
401-- | Write a stream of Strings to an IO Handle.
402+--
403+-- @since 0.1.0
358toHandle :: MonadIO m => IO.Handle -> StreamT m String -> m ()
404toHandle :: MonadIO m => IO.Handle -> StreamT m String -> m ()
359toHandle h m = go (toStream m)
405toHandle h m = go (toStream m)
360 where
406 where
@@ -369,11 +415,15 @@ toHandle h m = go (toStream m)
369------------------------------------------------------------------------------
415------------------------------------------------------------------------------
370
416
371-- | Convert a stream into a list in the underlying monad.
417-- | Convert a stream into a list in the underlying monad.
418+--
419+-- @since 0.1.0
372{-# INLINABLE toList #-}
420{-# INLINABLE toList #-}
373toList :: Monad m => StreamT m a -> m [a]
421toList :: Monad m => StreamT m a -> m [a]
374toList = foldrM (\a xs -> return (a : xs)) []
422toList = foldrM (\a xs -> return (a : xs)) []
375
423
376-- | Take first 'n' elements from the stream and discard the rest.
424-- | Take first 'n' elements from the stream and discard the rest.
425+--
426+-- @since 0.1.0
377{-# INLINE take #-}
427{-# INLINE take #-}
378take :: IsStream t => Int -> t m a -> t m a
428take :: IsStream t => Int -> t m a -> t m a
379take n m = fromStream $ go n (toStream m)
429take n m = fromStream $ go n (toStream m)
@@ -383,6 +433,8 @@ take n m = fromStream $ go n (toStream m)
383 in if n1 <= 0 then stp else (S.runStream m1) ctx stp sng yield
433 in if n1 <= 0 then stp else (S.runStream m1) ctx stp sng yield
384
434
385-- | Include only those elements that pass a predicate.
435-- | Include only those elements that pass a predicate.
436+--
437+-- @since 0.1.0
386{-# INLINE filter #-}
438{-# INLINE filter #-}
387filter :: IsStream t => (a -> Bool) -> t m a -> t m a
439filter :: IsStream t => (a -> Bool) -> t m a -> t m a
388filter p m = fromStream $ go (toStream m)
440filter p m = fromStream $ go (toStream m)
@@ -395,6 +447,8 @@ filter p m = fromStream $ go (toStream m)
395 in (S.runStream m1) ctx stp single yield
447 in (S.runStream m1) ctx stp single yield
396
448
397-- | End the stream as soon as the predicate fails on an element.
449-- | End the stream as soon as the predicate fails on an element.
450+--
451+-- @since 0.1.0
398{-# INLINE takeWhile #-}
452{-# INLINE takeWhile #-}
399takeWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
453takeWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
400takeWhile p m = fromStream $ go (toStream m)
454takeWhile p m = fromStream $ go (toStream m)
@@ -407,6 +461,8 @@ takeWhile p m = fromStream $ go (toStream m)
407 in (S.runStream m1) ctx stp single yield
461 in (S.runStream m1) ctx stp single yield
408
462
409-- | Discard first 'n' elements from the stream and take the rest.
463-- | Discard first 'n' elements from the stream and take the rest.
464+--
465+-- @since 0.1.0
410drop :: IsStream t => Int -> t m a -> t m a
466drop :: IsStream t => Int -> t m a -> t m a
411drop n m = fromStream $ go n (toStream m)
467drop n m = fromStream $ go n (toStream m)
412 where
468 where
@@ -420,6 +476,8 @@ drop n m = fromStream $ go n (toStream m)
420
476
421-- | Drop elements in the stream as long as the predicate succeeds and then
477-- | Drop elements in the stream as long as the predicate succeeds and then
422-- take the rest of the stream.
478-- take the rest of the stream.
479+--
480+-- @since 0.1.0
423{-# INLINE dropWhile #-}
481{-# INLINE dropWhile #-}
424dropWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
482dropWhile :: IsStream t => (a -> Bool) -> t m a -> t m a
425dropWhile p m = fromStream $ go (toStream m)
483dropWhile p m = fromStream $ go (toStream m)
@@ -432,6 +490,8 @@ dropWhile p m = fromStream $ go (toStream m)
432 in (S.runStream m1) ctx stp single yield
490 in (S.runStream m1) ctx stp single yield
433
491
434-- | Determine whether all elements of a stream satisfy a predicate.
492-- | Determine whether all elements of a stream satisfy a predicate.
493+--
494+-- @since 0.1.0
435all :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
495all :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
436all p m = go (toStream m)
496all p m = go (toStream m)
437 where
497 where
@@ -443,6 +503,8 @@ all p m = go (toStream m)
443 in (S.runStream m1) Nothing (return True) single yield
503 in (S.runStream m1) Nothing (return True) single yield
444
504
445-- | Determine whether any of the elements of a stream satisfy a predicate.
505-- | Determine whether any of the elements of a stream satisfy a predicate.
506+--
507+-- @since 0.1.0
446any :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
508any :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
447any p m = go (toStream m)
509any p m = go (toStream m)
448 where
510 where
@@ -454,14 +516,20 @@ any p m = go (toStream m)
454 in (S.runStream m1) Nothing (return False) single yield
516 in (S.runStream m1) Nothing (return False) single yield
455
517
456-- | Determine the sum of all elements of a stream of numbers
518-- | Determine the sum of all elements of a stream of numbers
519+--
520+-- @since 0.1.0
457sum :: (Monad m, Num a) => StreamT m a -> m a
521sum :: (Monad m, Num a) => StreamT m a -> m a
458sum = foldl (+) 0 id
522sum = foldl (+) 0 id
459
523
460-- | Determine the product of all elements of a stream of numbers
524-- | Determine the product of all elements of a stream of numbers
525+--
526+-- @since 0.1.1
461product :: (Monad m, Num a) => StreamT m a -> m a
527product :: (Monad m, Num a) => StreamT m a -> m a
462product = foldl (*) 1 id
528product = foldl (*) 1 id
463
529
464-- | Extract the first element of the stream, if any.
530-- | Extract the first element of the stream, if any.
531+--
532+-- @since 0.1.0
465head :: Monad m => StreamT m a -> m (Maybe a)
533head :: Monad m => StreamT m a -> m (Maybe a)
466head m =
534head m =
467 let stop = return Nothing
535 let stop = return Nothing
@@ -470,6 +538,8 @@ head m =
470 in (S.runStream (toStream m)) Nothing stop single yield
538 in (S.runStream (toStream m)) Nothing stop single yield
471
539
472-- | Extract all but the first element of the stream, if any.
540-- | Extract all but the first element of the stream, if any.
541+--
542+-- @since 0.1.1
473tail :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (t m a))
543tail :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (t m a))
474tail m =
544tail m =
475 let stop = return Nothing
545 let stop = return Nothing
@@ -478,11 +548,15 @@ tail m =
478 in (S.runStream (toStream m)) Nothing stop single yield
548 in (S.runStream (toStream m)) Nothing stop single yield
479
549
480-- | Extract the last element of the stream, if any.
550-- | Extract the last element of the stream, if any.
551+--
552+-- @since 0.1.1
481{-# INLINE last #-}
553{-# INLINE last #-}
482last :: Monad m => StreamT m a -> m (Maybe a)
554last :: Monad m => StreamT m a -> m (Maybe a)
483last = foldl (\_ y -> Just y) Nothing id
555last = foldl (\_ y -> Just y) Nothing id
484
556
485-- | Determine whether the stream is empty.
557-- | Determine whether the stream is empty.
558+--
559+-- @since 0.1.1
486null :: Monad m => StreamT m a -> m Bool
560null :: Monad m => StreamT m a -> m Bool
487null m =
561null m =
488 let stop = return True
562 let stop = return True
@@ -491,6 +565,8 @@ null m =
491 in (S.runStream (toStream m)) Nothing stop single yield
565 in (S.runStream (toStream m)) Nothing stop single yield
492
566
493-- | Determine whether an element is present in the stream.
567-- | Determine whether an element is present in the stream.
568+--
569+-- @since 0.1.0
494elem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
570elem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
495elem e m = go (toStream m)
571elem e m = go (toStream m)
496 where
572 where
@@ -501,6 +577,8 @@ elem e m = go (toStream m)
501 in (S.runStream m1) Nothing stop single yield
577 in (S.runStream m1) Nothing stop single yield
502
578
503-- | Determine whether an element is not present in the stream.
579-- | Determine whether an element is not present in the stream.
580+--
581+-- @since 0.1.0
504notElem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
582notElem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
505notElem e m = go (toStream m)
583notElem e m = go (toStream m)
506 where
584 where
@@ -511,11 +589,15 @@ notElem e m = go (toStream m)
511 in (S.runStream m1) Nothing stop single yield
589 in (S.runStream m1) Nothing stop single yield
512
590
513-- | Determine the length of the stream.
591-- | Determine the length of the stream.
592+--
593+-- @since 0.1.0
514length :: Monad m => StreamT m a -> m Int
594length :: Monad m => StreamT m a -> m Int
515length = foldl (\n _ -> n + 1) 0 id
595length = foldl (\n _ -> n + 1) 0 id
516
596
517-- | Returns the elements of the stream in reverse order.
597-- | Returns the elements of the stream in reverse order.
518-- The stream must be finite.
598-- The stream must be finite.
599+--
600+-- @since 0.1.1
519reverse :: (IsStream t) => t m a -> t m a
601reverse :: (IsStream t) => t m a -> t m a
520reverse m = fromStream $ go S.nil (toStream m)
602reverse m = fromStream $ go S.nil (toStream m)
521 where
603 where
@@ -528,6 +610,8 @@ reverse m = fromStream $ go S.nil (toStream m)
528
610
529-- XXX replace the recursive "go" with continuation
611-- XXX replace the recursive "go" with continuation
530-- | Determine the minimum element in a stream.
612-- | Determine the minimum element in a stream.
613+--
614+-- @since 0.1.0
531minimum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
615minimum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
532minimum m = go Nothing (toStream m)
616minimum m = go Nothing (toStream m)
533 where
617 where
@@ -543,6 +627,8 @@ minimum m = go Nothing (toStream m)
543
627
544-- XXX replace the recursive "go" with continuation
628-- XXX replace the recursive "go" with continuation
545-- | Determine the maximum element in a stream.
629-- | Determine the maximum element in a stream.
630+--
631+-- @since 0.1.0
546maximum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
632maximum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
547maximum m = go Nothing (toStream m)
633maximum m = go Nothing (toStream m)
548 where
634 where
@@ -564,6 +650,8 @@ maximum m = go Nothing (toStream m)
564
650
565-- | Replace each element of the stream with the result of a monadic action
651-- | Replace each element of the stream with the result of a monadic action
566-- applied on the element.
652-- applied on the element.
653+--
654+-- @since 0.1.0
567{-# INLINE mapM #-}
655{-# INLINE mapM #-}
568mapM :: (IsStream t, Monad m) => (a -> m b) -> t m a -> t m b
656mapM :: (IsStream t, Monad m) => (a -> m b) -> t m a -> t m b
569mapM f m = fromStream $ go (toStream m)
657mapM f m = fromStream $ go (toStream m)
@@ -575,6 +663,8 @@ mapM f m = fromStream $ go (toStream m)
575
663
576-- | Apply a monadic action to each element of the stream and discard the
664-- | Apply a monadic action to each element of the stream and discard the
577-- output of the action.
665-- output of the action.
666+--
667+-- @since 0.1.0
578mapM_ :: Monad m => (a -> m b) -> StreamT m a -> m ()
668mapM_ :: Monad m => (a -> m b) -> StreamT m a -> m ()
579mapM_ f m = go (toStream m)
669mapM_ f m = go (toStream m)
580 where
670 where
@@ -586,6 +676,8 @@ mapM_ f m = go (toStream m)
586
676
587-- | Reduce a stream of monadic actions to a stream of the output of those
677-- | Reduce a stream of monadic actions to a stream of the output of those
588-- actions.
678-- actions.
679+--
680+-- @since 0.1.0
589sequence :: (IsStream t, Monad m) => t m (m a) -> t m a
681sequence :: (IsStream t, Monad m) => t m (m a) -> t m a
590sequence m = fromStream $ go (toStream m)
682sequence m = fromStream $ go (toStream m)
591 where
683 where
@@ -599,10 +691,14 @@ sequence m = fromStream $ go (toStream m)
599------------------------------------------------------------------------------
691------------------------------------------------------------------------------
600
692
601-- | Zip two streams serially using a pure zipping function.
693-- | Zip two streams serially using a pure zipping function.
694+--
695+-- @since 0.1.0
602zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
696zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
603zipWith f m1 m2 = fromStream $ S.zipWith f (toStream m1) (toStream m2)
697zipWith f m1 m2 = fromStream $ S.zipWith f (toStream m1) (toStream m2)
604
698
605-- | Zip two streams serially using a monadic zipping function.
699-- | Zip two streams serially using a monadic zipping function.
700+--
701+-- @since 0.1.0
606zipWithM :: IsStream t => (a -> b -> t m c) -> t m a -> t m b -> t m c
702zipWithM :: IsStream t => (a -> b -> t m c) -> t m a -> t m b -> t m c
607zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
703zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
608 where
704 where
@@ -622,11 +718,15 @@ zipWithM f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
622
718
623-- | Zip two streams concurrently (i.e. both the elements being zipped are
719-- | Zip two streams concurrently (i.e. both the elements being zipped are
624-- generated concurrently) using a pure zipping function.
720-- generated concurrently) using a pure zipping function.
721+--
722+-- @since 0.2.0
625zipParallelWith :: (IsStream t, MonadParallel m)
723zipParallelWith :: (IsStream t, MonadParallel m)
626 => (a -> b -> c) -> t m a -> t m b -> t m c
724 => (a -> b -> c) -> t m a -> t m b -> t m c
627zipParallelWith f m1 m2 =
725zipParallelWith f m1 m2 =
628 fromStream $ S.zipParallelWith f (toStream m1) (toStream m2)
726 fromStream $ S.zipParallelWith f (toStream m1) (toStream m2)
629
727
728+-- |
729+-- @since 0.1.0
630{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
730{-# DEPRECATED zipAsyncWith "Please use zipParallelWith instead." #-}
631zipAsyncWith :: (IsStream t, MonadParallel m)
731zipAsyncWith :: (IsStream t, MonadParallel m)
632 => (a -> b -> c) -> t m a -> t m b -> t m c
732 => (a -> b -> c) -> t m a -> t m b -> t m c
@@ -634,6 +734,8 @@ zipAsyncWith = zipParallelWith
634
734
635-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
735-- | Zip two streams asyncly (i.e. both the elements being zipped are generated
636-- concurrently) using a monadic zipping function.
736-- concurrently) using a monadic zipping function.
737+--
738+-- @since 0.2.0
637zipParallelWithM :: (IsStream t, MonadParallel m)
739zipParallelWithM :: (IsStream t, MonadParallel m)
638 => (a -> b -> t m c) -> t m a -> t m b -> t m c
740 => (a -> b -> t m c) -> t m a -> t m b -> t m c
639zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
741zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
@@ -641,6 +743,8 @@ zipParallelWithM f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
641 mb <- async m2
743 mb <- async m2
642 (S.runStream (toStream (zipWithM f ma mb))) Nothing stp sng yld
744 (S.runStream (toStream (zipWithM f ma mb))) Nothing stp sng yld
643
745
746+-- |
747+-- @since 0.1.0
644{-# DEPRECATED zipAsyncWithM "Please use zipParallelWithM instead." #-}
748{-# DEPRECATED zipAsyncWithM "Please use zipParallelWithM instead." #-}
645zipAsyncWithM :: (IsStream t, MonadParallel m)
749zipAsyncWithM :: (IsStream t, MonadParallel m)
646 => (a -> b -> t m c) -> t m a -> t m b -> t m c
750 => (a -> b -> t m c) -> t m a -> t m b -> t m c
src/Streamly/Streams.hs+105−3
@@ -80,6 +80,7 @@ module Streamly.Streams
80
80
81 -- * Type Adapters
81 -- * Type Adapters
82 , streamly
82 , streamly
83+ , serially -- deprecated
83 , costreamly
84 , costreamly
84 , interleaving -- deprecated
85 , interleaving -- deprecated
85 , coparallely
86 , coparallely
@@ -126,12 +127,16 @@ import qualified Streamly.Core as S
126
127
127-- | Class of types that can represent a stream of elements of some type 'a' in
128-- | Class of types that can represent a stream of elements of some type 'a' in
128-- some monad 'm'.
129-- some monad 'm'.
130+--
131+-- @since 0.2.0
129class IsStream t where
132class IsStream t where
130 toStream :: t m a -> S.Stream m a
133 toStream :: t m a -> S.Stream m a
131 fromStream :: S.Stream m a -> t m a
134 fromStream :: S.Stream m a -> t m a
132
135
133-- | Same as 'IsStream'.
136-- | Same as 'IsStream'.
137+--
138+-- @since 0.1.0
134−{-# Deprecated Streaming "Please use IsStream instead." #-}
139+{-# DEPRECATED Streaming "Please use IsStream instead." #-}
135type Streaming = IsStream
140type Streaming = IsStream
136
141
137------------------------------------------------------------------------------
142------------------------------------------------------------------------------
@@ -144,6 +149,8 @@ type Streaming = IsStream
144-- > toList nil
149-- > toList nil
145-- []
150-- []
146-- @
151-- @
152+--
153+-- @since 0.1.0
147nil :: IsStream t => t m a
154nil :: IsStream t => t m a
148nil = fromStream S.nil
155nil = fromStream S.nil
149
156
@@ -158,6 +165,8 @@ infixr 5 `consM`
158-- world
165-- world
159-- ["hello","world"]
166-- ["hello","world"]
160-- @
167-- @
168+--
169+-- @since 0.2.0
161consM :: (IsStream t, Monad m) => m a -> t m a -> t m a
170consM :: (IsStream t, Monad m) => m a -> t m a -> t m a
162consM m r = fromStream $ S.consM m (toStream r)
171consM m r = fromStream $ S.consM m (toStream r)
163
172
@@ -171,6 +180,8 @@ infixr 5 |:
171-- world
180-- world
172-- ["hello","world"]
181-- ["hello","world"]
173-- @
182-- @
183+--
184+-- @since 0.2.0
174(|:) :: (IsStream t, Monad m) => m a -> t m a -> t m a
185(|:) :: (IsStream t, Monad m) => m a -> t m a -> t m a
175(|:) = consM
186(|:) = consM
176
187
@@ -183,6 +194,8 @@ infixr 5 `cons`
183-- > toList $ 1 \`cons` 2 \`cons` 3 \`cons` nil
194-- > toList $ 1 \`cons` 2 \`cons` 3 \`cons` nil
184-- [1,2,3]
195-- [1,2,3]
185-- @
196-- @
197+--
198+-- @since 0.1.0
186cons :: IsStream t => a -> t m a -> t m a
199cons :: IsStream t => a -> t m a -> t m a
187cons a r = fromStream $ S.cons a (toStream r)
200cons a r = fromStream $ S.cons a (toStream r)
188
201
@@ -195,6 +208,7 @@ infixr 5 .:
195-- [1,2,3]
208-- [1,2,3]
196-- @
209-- @
197--
210--
211+-- @since 0.1.1
198(.:) :: IsStream t => a -> t m a -> t m a
212(.:) :: IsStream t => a -> t m a -> t m a
199(.:) = cons
213(.:) = cons
200
214
@@ -244,6 +258,8 @@ streamFold svr step single blank m =
244-- | Run a streaming composition, discard the results. By default it interprets
258-- | Run a streaming composition, discard the results. By default it interprets
245-- the stream as 'StreamT', to run other types of streams use the type adapting
259-- the stream as 'StreamT', to run other types of streams use the type adapting
246-- combinators for example @runStream . 'parallely'@.
260-- combinators for example @runStream . 'parallely'@.
261+--
262+-- @since 0.2.0
247runStream :: Monad m => StreamT m a -> m ()
263runStream :: Monad m => StreamT m a -> m ()
248runStream m = go (toStream m)
264runStream m = go (toStream m)
249 where
265 where
@@ -254,7 +270,9 @@ runStream m = go (toStream m)
254 in (S.runStream m1) Nothing stop single yield
270 in (S.runStream m1) Nothing stop single yield
255
271
256-- | Same as 'runStream'
272-- | Same as 'runStream'
273+--
274+-- @since 0.1.0
257−{-# Deprecated runStreaming "Please use runStream instead." #-}
275+{-# DEPRECATED runStreaming "Please use runStream instead." #-}
258runStreaming :: (Monad m, IsStream t) => t m a -> m ()
276runStreaming :: (Monad m, IsStream t) => t m a -> m ()
259runStreaming = runStream . adapt
277runStreaming = runStream . adapt
260
278
@@ -273,7 +291,8 @@ toSVar sv m = S.toStreamVar sv (toStream m)
273-- computation. The returned action is exhaustible and must be drained once. If
291-- computation. The returned action is exhaustible and must be drained once. If
274-- not drained fully we may have a thread blocked forever and once exhausted it
292-- not drained fully we may have a thread blocked forever and once exhausted it
275-- will always return 'empty'.
293-- will always return 'empty'.
276−
294+--
295+-- @since 0.1.0
277async :: (IsStream t, MonadParallel m) => t m a -> m (t m a)
296async :: (IsStream t, MonadParallel m) => t m a -> m (t m a)
278async m = do
297async m = do
279 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
298 sv <- S.newStreamVar1 (SVarStyle Disjunction LIFO) (toStream m)
@@ -373,6 +392,7 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
373-- Note that serial composition can be used to combine an infinite number of
392-- Note that serial composition can be used to combine an infinite number of
374-- streams as it explores only one stream at a time.
393-- streams as it explores only one stream at a time.
375--
394--
395+-- @since 0.1.0
376newtype StreamT m a = StreamT {getStreamT :: S.Stream m a}
396newtype StreamT m a = StreamT {getStreamT :: S.Stream m a}
377 deriving (Semigroup, Monoid, Functor, MonadTrans)
397 deriving (Semigroup, Monoid, Functor, MonadTrans)
378
398
@@ -387,6 +407,8 @@ instance IsStream StreamT where
387-- | Polymorphic version of the 'Semigroup' operation '<>' of 'StreamT'.
407-- | Polymorphic version of the 'Semigroup' operation '<>' of 'StreamT'.
388-- Appends two streams sequentially, yielding all elements from the first
408-- Appends two streams sequentially, yielding all elements from the first
389-- stream, and then all elements from the second stream.
409-- stream, and then all elements from the second stream.
410+--
411+-- @since 0.2.0
390{-# INLINE splice #-}
412{-# INLINE splice #-}
391splice :: IsStream t => t m a -> t m a -> t m a
413splice :: IsStream t => t m a -> t m a -> t m a
392splice m1 m2 = fromStream $ S.splice (toStream m1) (toStream m2)
414splice m1 m2 = fromStream $ S.splice (toStream m1) (toStream m2)
@@ -444,9 +466,12 @@ MONAD_COMMON_INSTANCES(StreamT,)
444-- Note that costreamly composition can only combine a finite number of
466-- Note that costreamly composition can only combine a finite number of
445-- streams as it needs to retain state for each unfinished stream.
467-- streams as it needs to retain state for each unfinished stream.
446--
468--
469+-- @since 0.2.0
447newtype CostreamT m a = CostreamT {getCostreamT :: S.Stream m a}
470newtype CostreamT m a = CostreamT {getCostreamT :: S.Stream m a}
448 deriving (Functor, MonadTrans)
471 deriving (Functor, MonadTrans)
449
472
473+-- |
474+-- @since 0.1.0
450{-# DEPRECATED InterleavedT "Please use 'CostreamT' instead." #-}
475{-# DEPRECATED InterleavedT "Please use 'CostreamT' instead." #-}
451type InterleavedT = CostreamT
476type InterleavedT = CostreamT
452
477
@@ -460,6 +485,8 @@ instance IsStream CostreamT where
460
485
461-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CostreamT'.
486-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CostreamT'.
462-- Interleaves two streams, yielding one element from each stream alternately.
487-- Interleaves two streams, yielding one element from each stream alternately.
488+--
489+-- @since 0.2.0
463{-# INLINE cosplice #-}
490{-# INLINE cosplice #-}
464cosplice :: IsStream t => t m a -> t m a -> t m a
491cosplice :: IsStream t => t m a -> t m a -> t m a
465cosplice m1 m2 = fromStream $ S.cosplice (toStream m1) (toStream m2)
492cosplice m1 m2 = fromStream $ S.cosplice (toStream m1) (toStream m2)
@@ -470,6 +497,8 @@ instance Semigroup (CostreamT m a) where
470infixr 5 <=>
497infixr 5 <=>
471
498
472-- | Same as 'cosplice'.
499-- | Same as 'cosplice'.
500+--
501+-- @since 0.1.0
473{-# DEPRECATED (<=>) "Please use 'cosplice' instead." #-}
502{-# DEPRECATED (<=>) "Please use 'cosplice' instead." #-}
474{-# INLINE (<=>) #-}
503{-# INLINE (<=>) #-}
475(<=>) :: IsStream t => t m a -> t m a -> t m a
504(<=>) :: IsStream t => t m a -> t m a -> t m a
@@ -545,9 +574,12 @@ MONAD_COMMON_INSTANCES(CostreamT,)
545-- Note that this composition can be used to combine infinite number of streams
574-- Note that this composition can be used to combine infinite number of streams
546-- as it explores only a bounded number of streams at a time.
575-- as it explores only a bounded number of streams at a time.
547--
576--
577+-- @since 0.2.0
548newtype CoparallelT m a = CoparallelT {getCoparallelT :: S.Stream m a}
578newtype CoparallelT m a = CoparallelT {getCoparallelT :: S.Stream m a}
549 deriving (Functor, MonadTrans)
579 deriving (Functor, MonadTrans)
550
580
581+-- |
582+-- @since 0.1.0
551{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
583{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
552type AsyncT = CoparallelT
584type AsyncT = CoparallelT
553
585
@@ -562,6 +594,8 @@ instance IsStream CoparallelT where
562-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT'.
594-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoparallelT'.
563-- Merges two streams possibly concurrently, preferring the
595-- Merges two streams possibly concurrently, preferring the
564-- elements from the left one when available.
596-- elements from the left one when available.
597+--
598+-- @since 0.2.0
565{-# INLINE coparallel #-}
599{-# INLINE coparallel #-}
566coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
600coparallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
567coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
601coparallel m1 m2 = fromStream $ S.coparallel (toStream m1) (toStream m2)
@@ -570,6 +604,8 @@ instance MonadParallel m => Semigroup (CoparallelT m a) where
570 (<>) = coparallel
604 (<>) = coparallel
571
605
572-- | Same as 'coparallel'.
606-- | Same as 'coparallel'.
607+--
608+-- @since 0.1.0
573{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
609{-# DEPRECATED (<|) "Please use 'coparallel' instead." #-}
574{-# INLINE (<|) #-}
610{-# INLINE (<|) #-}
575(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
611(<|) :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
@@ -655,6 +691,7 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
655-- Note that round robin composition can only combine a finite number of
691-- Note that round robin composition can only combine a finite number of
656-- streams as it needs to retain state for each unfinished stream.
692-- streams as it needs to retain state for each unfinished stream.
657--
693--
694+-- @since 0.1.0
658newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
695newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
659 deriving (Functor, MonadTrans)
696 deriving (Functor, MonadTrans)
660
697
@@ -668,6 +705,8 @@ instance IsStream ParallelT where
668
705
669-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
706-- | Polymorphic version of the 'Semigroup' operation '<>' of 'ParallelT'.
670-- Merges two streams concurrently choosing elements from both fairly.
707-- Merges two streams concurrently choosing elements from both fairly.
708+--
709+-- @since 0.2.0
671{-# INLINE parallel #-}
710{-# INLINE parallel #-}
672parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
711parallel :: (IsStream t, MonadParallel m) => t m a -> t m a -> t m a
673parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
712parallel m1 m2 = fromStream $ S.parallel (toStream m1) (toStream m2)
@@ -720,6 +759,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
720-- The 'Semigroup' instance of this type works the same way as that of
759-- The 'Semigroup' instance of this type works the same way as that of
721-- 'StreamT'.
760-- 'StreamT'.
722--
761--
762+-- @since 0.2.0
723newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: S.Stream m a}
763newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: S.Stream m a}
724 deriving (Functor, Semigroup, Monoid)
764 deriving (Functor, Semigroup, Monoid)
725
765
@@ -751,9 +791,12 @@ instance Monad m => Applicative (ZipStreamM m) where
751-- The 'Semigroup' instance of this type works the same way as that of
791-- The 'Semigroup' instance of this type works the same way as that of
752-- 'StreamT'.
792-- 'StreamT'.
753--
793--
794+-- @since 0.2.0
754newtype ZipParallelM m a = ZipParallelM {getZipParallelM :: S.Stream m a}
795newtype ZipParallelM m a = ZipParallelM {getZipParallelM :: S.Stream m a}
755 deriving (Functor, Semigroup, Monoid)
796 deriving (Functor, Semigroup, Monoid)
756
797
798+-- |
799+-- @since 0.1.0
757{-# DEPRECATED ZipAsync "Please use ZipParallelM instead." #-}
800{-# DEPRECATED ZipAsync "Please use ZipParallelM instead." #-}
758type ZipAsync = ZipParallelM
801type ZipAsync = ZipParallelM
759
802
@@ -770,49 +813,78 @@ instance MonadParallel m => Applicative (ZipParallelM m) where
770-------------------------------------------------------------------------------
813-------------------------------------------------------------------------------
771
814
772-- | Adapt any specific stream type to any other specific stream type.
815-- | Adapt any specific stream type to any other specific stream type.
816+--
817+-- @since 0.1.0
773adapt :: (IsStream t1, IsStream t2) => t1 m a -> t2 m a
818adapt :: (IsStream t1, IsStream t2) => t1 m a -> t2 m a
774adapt = fromStream . toStream
819adapt = fromStream . toStream
775
820
776-- | Fix the type of a polymorphic stream as 'StreamT'.
821-- | Fix the type of a polymorphic stream as 'StreamT'.
822+--
823+-- @since 0.2.0
777streamly :: IsStream t => StreamT m a -> t m a
824streamly :: IsStream t => StreamT m a -> t m a
778streamly = adapt
825streamly = adapt
779
826
827+-- | Same as 'streamly'.
828+--
829+-- @since 0.1.0
830+{-# DEPRECATED serially "Please use streamly instead." #-}
831+serially :: IsStream t => StreamT m a -> t m a
832+serially = streamly
833+
780-- | Fix the type of a polymorphic stream as 'CostreamT'.
834-- | Fix the type of a polymorphic stream as 'CostreamT'.
835+--
836+-- @since 0.2.0
781costreamly :: IsStream t => CostreamT m a -> t m a
837costreamly :: IsStream t => CostreamT m a -> t m a
782costreamly = adapt
838costreamly = adapt
783
839
784-- | Same as 'costreamly'.
840-- | Same as 'costreamly'.
841+--
842+-- @since 0.1.0
785{-# DEPRECATED interleaving "Please use costreamly instead." #-}
843{-# DEPRECATED interleaving "Please use costreamly instead." #-}
786interleaving :: IsStream t => CostreamT m a -> t m a
844interleaving :: IsStream t => CostreamT m a -> t m a
787interleaving = costreamly
845interleaving = costreamly
788
846
789-- | Fix the type of a polymorphic stream as 'CoparallelT'.
847-- | Fix the type of a polymorphic stream as 'CoparallelT'.
848+--
849+-- @since 0.2.0
790coparallely :: IsStream t => CoparallelT m a -> t m a
850coparallely :: IsStream t => CoparallelT m a -> t m a
791coparallely = adapt
851coparallely = adapt
792
852
793-- | Same as 'coparallely'.
853-- | Same as 'coparallely'.
854+--
855+-- @since 0.1.0
794{-# DEPRECATED asyncly "Please use coparallely instead." #-}
856{-# DEPRECATED asyncly "Please use coparallely instead." #-}
795asyncly :: IsStream t => CoparallelT m a -> t m a
857asyncly :: IsStream t => CoparallelT m a -> t m a
796asyncly = coparallely
858asyncly = coparallely
797
859
798-- | Fix the type of a polymorphic stream as 'ParallelT'.
860-- | Fix the type of a polymorphic stream as 'ParallelT'.
861+--
862+-- @since 0.1.0
799parallely :: IsStream t => ParallelT m a -> t m a
863parallely :: IsStream t => ParallelT m a -> t m a
800parallely = adapt
864parallely = adapt
801
865
802-- | Fix the type of a polymorphic stream as 'ZipStreamM'.
866-- | Fix the type of a polymorphic stream as 'ZipStreamM'.
867+--
868+-- @since 0.2.0
803zipStreamly :: IsStream t => ZipStreamM m a -> t m a
869zipStreamly :: IsStream t => ZipStreamM m a -> t m a
804zipStreamly = adapt
870zipStreamly = adapt
805
871
806-- | Same as 'zipStreamly'.
872-- | Same as 'zipStreamly'.
873+--
874+-- @since 0.1.0
807{-# DEPRECATED zipping "Please use zipStreamly instead." #-}
875{-# DEPRECATED zipping "Please use zipStreamly instead." #-}
808zipping :: IsStream t => ZipStreamM m a -> t m a
876zipping :: IsStream t => ZipStreamM m a -> t m a
809zipping = zipStreamly
877zipping = zipStreamly
810
878
811-- | Fix the type of a polymorphic stream as 'ZipParallelM'.
879-- | Fix the type of a polymorphic stream as 'ZipParallelM'.
880+--
881+-- @since 0.2.0
812zipParallely :: IsStream t => ZipParallelM m a -> t m a
882zipParallely :: IsStream t => ZipParallelM m a -> t m a
813zipParallely = adapt
883zipParallely = adapt
814
884
815-- | Same as 'zipParallely'.
885-- | Same as 'zipParallely'.
886+--
887+-- @since 0.1.0
816{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
888{-# DEPRECATED zippingAsync "Please use zipParallely instead." #-}
817zippingAsync :: IsStream t => ZipParallelM m a -> t m a
889zippingAsync :: IsStream t => ZipParallelM m a -> t m a
818zippingAsync = zipParallely
890zippingAsync = zipParallely
@@ -822,31 +894,43 @@ zippingAsync = zipParallely
822-------------------------------------------------------------------------------
894-------------------------------------------------------------------------------
823
895
824-- | Same as @runStream@.
896-- | Same as @runStream@.
897+--
898+-- @since 0.1.0
825{-# DEPRECATED runStreamT "Please use runStream instead." #-}
899{-# DEPRECATED runStreamT "Please use runStream instead." #-}
826runStreamT :: Monad m => StreamT m a -> m ()
900runStreamT :: Monad m => StreamT m a -> m ()
827runStreamT = runStream
901runStreamT = runStream
828
902
829-- | Same as @runStream . costreamly@.
903-- | Same as @runStream . costreamly@.
904+--
905+-- @since 0.1.0
830{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
906{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
831runInterleavedT :: Monad m => InterleavedT m a -> m ()
907runInterleavedT :: Monad m => InterleavedT m a -> m ()
832runInterleavedT = runStream . costreamly
908runInterleavedT = runStream . costreamly
833
909
834-- | Same as @runStream . coparallely@.
910-- | Same as @runStream . coparallely@.
911+--
912+-- @since 0.1.0
835{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
913{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
836runAsyncT :: Monad m => CoparallelT m a -> m ()
914runAsyncT :: Monad m => CoparallelT m a -> m ()
837runAsyncT = runStream . coparallely
915runAsyncT = runStream . coparallely
838
916
839-- | Same as @runStream . parallely@.
917-- | Same as @runStream . parallely@.
918+--
919+-- @since 0.1.0
840{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
920{-# DEPRECATED runParallelT "Please use 'runStream . parallely' instead." #-}
841runParallelT :: Monad m => ParallelT m a -> m ()
921runParallelT :: Monad m => ParallelT m a -> m ()
842runParallelT = runStream . parallely
922runParallelT = runStream . parallely
843
923
844-- | Same as @runStream . zipping@.
924-- | Same as @runStream . zipping@.
925+--
926+-- @since 0.1.0
845{-# DEPRECATED runZipStream "Please use 'runStream . zipStreamly instead." #-}
927{-# DEPRECATED runZipStream "Please use 'runStream . zipStreamly instead." #-}
846runZipStream :: Monad m => ZipStreamM m a -> m ()
928runZipStream :: Monad m => ZipStreamM m a -> m ()
847runZipStream = runStream . zipStreamly
929runZipStream = runStream . zipStreamly
848
930
849-- | Same as @runStream . zippingAsync@.
931-- | Same as @runStream . zippingAsync@.
932+--
933+-- @since 0.1.0
850{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
934{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
851runZipAsync :: Monad m => ZipParallelM m a -> m ()
935runZipAsync :: Monad m => ZipParallelM m a -> m ()
852runZipAsync = runStream . zipParallely
936runZipAsync = runStream . zipParallely
@@ -857,24 +941,36 @@ runZipAsync = runStream . zipParallely
857
941
858-- | A serial IO stream of elements of type @a@. See 'StreamT' documentation
942-- | A serial IO stream of elements of type @a@. See 'StreamT' documentation
859-- for more details.
943-- for more details.
944+--
945+-- @since 0.2.0
860type Stream a = StreamT IO a
946type Stream a = StreamT IO a
861
947
862-- | An interleaving serial IO stream of elements of type @a@. See 'CostreamT'
948-- | An interleaving serial IO stream of elements of type @a@. See 'CostreamT'
863-- documentation for more details.
949-- documentation for more details.
950+--
951+-- @since 0.2.0
864type Costream a = CostreamT IO a
952type Costream a = CostreamT IO a
865
953
866-- | A demand driven left biased parallelly composing IO stream of elements of
954-- | A demand driven left biased parallelly composing IO stream of elements of
867-- type @a@. See 'CoparallelT' documentation for more details.
955-- type @a@. See 'CoparallelT' documentation for more details.
956+--
957+-- @since 0.2.0
868type Coparallel a = CoparallelT IO a
958type Coparallel a = CoparallelT IO a
869
959
870-- | A round robin parallelly composing IO stream of elements of type @a@.
960-- | A round robin parallelly composing IO stream of elements of type @a@.
871-- See 'ParallelT' documentation for more details.
961-- See 'ParallelT' documentation for more details.
962+--
963+-- @since 0.2.0
872type Parallel a = ParallelT IO a
964type Parallel a = ParallelT IO a
873
965
874-- | An IO stream whose applicative instance zips streams serially.
966-- | An IO stream whose applicative instance zips streams serially.
967+--
968+-- @since 0.2.0
875type ZipStream a = ZipStreamM IO a
969type ZipStream a = ZipStreamM IO a
876
970
877-- | An IO stream whose applicative instance zips streams parallely.
971-- | An IO stream whose applicative instance zips streams parallely.
972+--
973+-- @since 0.2.0
878type ZipParallel a = ZipParallelM IO a
974type ZipParallel a = ZipParallelM IO a
879
975
880------------------------------------------------------------------------------
976------------------------------------------------------------------------------
@@ -885,6 +981,8 @@ type ZipParallel a = ZipParallelM IO a
885-- container of streams using the specified stream sum operation.
981-- container of streams using the specified stream sum operation.
886--
982--
887-- @foldWith 'parallel' $ map return [1..3]@
983-- @foldWith 'parallel' $ map return [1..3]@
984+--
985+-- @since 0.1.0
888{-# INLINABLE foldWith #-}
986{-# INLINABLE foldWith #-}
889foldWith :: (IsStream t, Foldable f)
987foldWith :: (IsStream t, Foldable f)
890 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
988 => (t m a -> t m a -> t m a) -> f (t m a) -> t m a
@@ -895,6 +993,8 @@ foldWith f = foldr f nil
895-- operation.
993-- operation.
896--
994--
897-- @foldMapWith 'parallel' return [1..3]@
995-- @foldMapWith 'parallel' return [1..3]@
996+--
997+-- @since 0.1.0
898{-# INLINABLE foldMapWith #-}
998{-# INLINABLE foldMapWith #-}
899foldMapWith :: (IsStream t, Foldable f)
999foldMapWith :: (IsStream t, Foldable f)
900 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
1000 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
@@ -902,6 +1002,8 @@ foldMapWith f g = foldr (f . g) nil
902
1002
903-- | Like 'foldMapWith' but with the last two arguments reversed i.e. the
1003-- | Like 'foldMapWith' but with the last two arguments reversed i.e. the
904-- monadic streaming function is the last argument.
1004-- monadic streaming function is the last argument.
1005+--
1006+-- @since 0.1.0
905{-# INLINABLE forEachWith #-}
1007{-# INLINABLE forEachWith #-}
906forEachWith :: (IsStream t, Foldable f)
1008forEachWith :: (IsStream t, Foldable f)
907 => (t m b -> t m b -> t m b) -> f a -> (a -> t m b) -> t m b
1009 => (t m b -> t m b -> t m b) -> f a -> (a -> t m b) -> t m b
src/Streamly/Time.hs+4
@@ -20,6 +20,8 @@ import Control.Concurrent (threadDelay)
20
20
21-- | Run an action forever periodically at the given frequency specified in per
21-- | Run an action forever periodically at the given frequency specified in per
22-- second (Hz).
22-- second (Hz).
23+--
24+-- @since 0.1.0
23periodic :: Int -> IO () -> IO ()
25periodic :: Int -> IO () -> IO ()
24periodic freq action = do
26periodic freq action = do
25 action
27 action
@@ -33,6 +35,8 @@ periodic freq action = do
33-- of time in microseconds. The second argument is the frequency in per second
35-- of time in microseconds. The second argument is the frequency in per second
34-- (Hz). The third argument is the action to run, the action is provided the
36-- (Hz). The third argument is the action to run, the action is provided the
35-- local time as an argument.
37-- local time as an argument.
38+--
39+-- @since 0.1.0
36withClock :: IO Int -> Int -> (Int -> IO ()) -> IO ()
40withClock :: IO Int -> Int -> (Int -> IO ()) -> IO ()
37withClock clock freq action = do
41withClock clock freq action = do
38 t <- clock
42 t <- clock
streamly.cabal+2−2
@@ -1,5 +1,5 @@
1name: streamly
1name: streamly
2−version: 0.1.2
2+version: 0.2.0
3synopsis: Beautiful Streaming, Concurrent and Reactive Composition
3synopsis: Beautiful Streaming, Concurrent and Reactive Composition
4description:
4description:
5 Streamly, short for streaming concurrently, is a simple yet powerful
5 Streamly, short for streaming concurrently, is a simple yet powerful
@@ -50,7 +50,7 @@ homepage: https://github.com/composewell/streamly
50bug-reports: https://github.com/composewell/streamly/issues
50bug-reports: https://github.com/composewell/streamly/issues
51license: BSD3
51license: BSD3
52license-file: LICENSE
52license-file: LICENSE
53−tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.1
53+tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.2
54author: Harendra Kumar
54author: Harendra Kumar
55maintainer: harendra.kumar@gmail.com
55maintainer: harendra.kumar@gmail.com
56copyright: 2017 Harendra Kumar
56copyright: 2017 Harendra Kumar