streaming
an elementary streaming prelude and general stream type.
This package contains two modules, <http://hackage.haskell.org/package/streaming/docs/Streaming.html Streaming>
and <http://hackage.haskell.org/package/streaming/docs/Streaming-Prelude.html Streaming.Prelude>.
The principal module, <http://hackage.haskell.org/package/streaming-0.1.4.3/docs/Streaming-Prelude.html Streaming.Prelude>, exports an elementary streaming prelude focused on
a simple \"source\" or \"producer\" type, namely @Stream (Of a) m r@.
This is a sort of effectful version of
@([a],r)@ in which successive elements of type @a@ arise from some sort of monadic
action before the succession ends with a value of type @r@.
Everything in the library is organized to make
programming with this type as simple as possible,
by the simple expedient of making it as close to @Prelude@
and @Data.List@ as possible. Thus for example
the trivial program
> >>> S.sum $ S.take 3 (S.readLn :: Stream (Of Int) IO ())
> 1<Enter>
> 2<Enter>
> 3<Enter>
> 6 :> ()
sums the first three valid integers from user input. Similarly,
> >>> S.stdoutLn $ S.map (map toUpper) $ S.take 2 S.stdinLn
> hello<Enter>
> HELLO
> world!<Enter>
> WORLD!
upper-cases the first two lines from stdin as they arise,
and sends them to stdout. And so on,
with filtering, mapping, breaking, chunking, zipping, unzipping, replicating
and so forth:
we program with streams of @Int@s or @String@s directly as
if they constituted something like a list. That's because streams really do constitute something
like a list, and the associated operations can mostly have the same names.
(A few, like @reverse@, don't stream and thus disappear;
others like @unzip@ are here given properly streaming formulation for the first time.)
And we everywhere
oppose \"extracting a pure list from IO\",
which is the origin of typical Haskell memory catastrophes.
Basically any case where you are
tempted to use @mapM@, @replicateM@, @traverse@ or @sequence@
with Haskell lists, you would do better to use something like
@Stream (Of a) m r@. The type signatures are a little fancier, but
the programs themselves are mostly the same. /In fact, they are mostly simpler./ Thus,
consider the trivial demo program mentioned in
<http://stackoverflow.com/questions/24068399/haskell-performance-of-iorefs this SO question>
> main = mapM newIORef [1..10^8::Int] >>= mapM readIORef >>= mapM_ print
The new user notices that this exhausts memory, and worries about the efficiency of Haskell @IORefs@.
But of course it exhausts memory! Look what it says!
The problem is immediately cured by writing
> main = S.print $ S.mapM readIORef $ S.mapM newIORef $ S.each [1..10^8::Int]
which really does what the other program was meant to do,
uses no more memory than @hello-world@, /and is simpler anyway/, since it
doesn't involve the detour of \"extracting a list from IO\". Almost
every use of list @mapM@, @replicateM@, @traverse@ and @sequence@ produces
this problem on a smaller scale. People get used to it, as if it were
characteristic of Haskell programs to use a lot of memory. But in truth
\"extracting a list or sequence from IO\" is mostly just bad practice pure and simple.
Of course, @mapM@, @replicateM@, @traverse@ and @sequence@ make sense for lists,
under certain conditions! But @unsafePerformIO@ also makes sense under
certain conditions.
The <http://hackage.haskell.org/package/streaming-0.1.4.3/docs/Streaming.html Streaming> module exports the general type,
@Stream f m r@, which can be used to stream successive distinct
steps characterized by /any/
functor @f@, though we are mostly interested in organizing computations
of the form @Stream (Of a) m r@. The streaming-IO libraries have
various devices for dealing
with effectful variants of @[a]@ or @([a],r)@ in which the emergence of
successive elements somehow depends on IO. But it is only with
the general type @Stream f m r@, or some equivalent,
that one can envisage (for example) the connected streaming of their
sorts of stream - as one makes lists of lists in the Haskell
@Prelude@ and @Data.List@. One needs some such type if we are
to express properly streaming equivalents of e.g.
> group :: Ord a => [a] -> [[a]]
> chunksOf :: Int -> [a] -> [[a]]
> lines :: [Char] -> [[Char]] -- but similarly with byte streams, etc.
to mention a few obviously desirable operations.
(This is explained more elaborately in the <https://hackage.haskell.org/package/streaming#readme readme> below.)
One could of course throw something
like the present @Stream@ type on top of a prior stream concept: this is how @pipes@ and
@pipes-group@ (which are very much our model here) use @FreeT@.
But once one grasps the iterable stream concept needed to express
those functions then one will also see that,
with it, one is /already/ in possession of a complete
elementary streaming library - since one possesses @Stream ((,) a) m r@
or equivalently @Stream (Of a) m r@. This
is the type of a \'generator\' or \'producer\' or \'source\' or whatever
you call an effectful stream of items.
/The present Streaming.Prelude is thus the simplest streaming library that can replicate anything like the API of the Prelude and Data.List/.
The emphasis of the library is on interoperation; for
the rest its advantages are: extreme simplicity, re-use of
intuitions the user has gathered from mastery of @Prelude@ and
@Data.List@, and a total and systematic rejection of type synonyms.
The two conceptual pre-requisites are some
comprehension of monad transformers and some familiarity
with \'rank 2 types\'. It is hoped that experimentation with this
simple material, starting with the ghci examples in @Streaming.Prelude@,
will give people who are new to these concepts some
intuition about their importance. The most fundamental purpose of the
library is to express elementary streaming ideas without reliance on
a complex framework, but in a way that integrates transparently with
the rest of Haskell, using ideas - e.g. rank 2 types, which are here
implicit or explicit in most mapping - that the user can carry elsewhere,
rather than chaining her understanding to the curiosities of
a so-called streaming IO framework (as necessary as that is for certain purposes.)
See the
<https://hackage.haskell.org/package/streaming#readme readme>
below for further explanation, including the examples linked there.
Elementary usage can be divined from the ghci examples in
@Streaming.Prelude@ and perhaps from this rough beginning of a
<https://github.com/michaelt/streaming-tutorial/blob/master/tutorial.md tutorial>.
Note also the
<https://hackage.haskell.org/package/streaming-bytestring streaming bytestring>
and
<https://hackage.haskell.org/package/streaming-utils streaming utils>
packages. Questions about usage can be put
raised on StackOverflow with the tag @[haskell-streaming]@,
or as an issue on Github, or on the
<https://groups.google.com/forum/#!forum/haskell-pipes pipes list>
(the package understands itself as part of the pipes \'ecosystem\'.)
The simplest form of interoperation with
<http://hackage.haskell.org/package/pipes pipes>
is accomplished with this isomorphism:
> Pipes.unfoldr Streaming.next :: Stream (Of a) m r -> Producer a m r
> Streaming.unfoldr Pipes.next :: Producer a m r -> Stream (Of a) m r
Interoperation with
<http://hackage.haskell.org/package/io-streams io-streams>
is thus:
> Streaming.reread IOStreams.read :: InputStream a -> Stream (Of a) IO ()
> IOStreams.unfoldM Streaming.uncons :: Stream (Of a) IO () -> IO (InputStream a)
With
<http://hackage.haskell.org/package/conduit conduit>
one might use, e.g.:
> Conduit.unfoldM Streaming.uncons :: Stream (Of a) m () -> Source m a
> \str -> Streaming.mapM_ Conduit.yield (hoist lift str) :: Stream (Of o) m r -> ConduitM i o m r
> \src -> hoist lift str $$ Conduit.mapM_ Streaming.yield :: Source m a -> Stream (Of a) m ()
These conversions should never be more expensive than a single @>->@ or @=$=@.
The simplest interoperation with regular Haskell lists is provided by, say
> Streaming.each :: [a] -> Stream (Of a) m ()
> Streaming.toList_ :: Stream (Of a) m r -> m [a]
The latter of course accumulates the whole list in memory, and is mostly what we are trying
to avoid. Every use of @Prelude.mapM f@ should be reconceived as using the
composition @Streaming.toList_ . Streaming.mapM f . Streaming.each@ with a view to
considering whether the accumulation required by @Streaming.toList_@ is really necessary.
Here are the results of some
<https://gist.github.com/michaelt/96606bbf05b29bf43a05aba081dc9bd4#file-benchmachines-hs microbenchmarks>
based on the
<https://github.com/ekmett/machines/blob/master/benchmarks/Benchmarks.hs benchmarks>
included in the machines package:
<<http://i.imgur.com/YbQtlXm.png>>
Because these are microbenchmarks for individual functions,
they represent a sort of \"worst case\"; many other factors can influence
the speed of a complex program.
| version | uploaded | uploader | changes | |
|---|---|---|---|---|
| 0.2.4.0 | 2023-07-06 15:25 UTC | OliverCharles | +21/−15 lines, 4 filesdep ~basedep ~mtldep ~transformersnew-uploaderPVP: major bump suggested | |
| 0.2.3.1 | 2021-12-20 20:05 UTC | chessai | 1 revisions | +382/−24 lines, 6 filesdep +QuickCheckdep +hspecdep +streamingdep ~basedep ~mmorphPVP: major bump suggested |
| 0.2.3.0 | 2019-09-24 16:28 UTC | chessai | 1 revisions | +486/−499 lines, 7 filesdep +faildep ~basedep ~transformersPVP: major bump suggested |
| 0.2.2.0 | 2018-10-03 01:15 UTC | chessai | 2 revisions | +225/−19 lines, 4 filesdep ~semigroupsnew-uploaderPVP: major bump suggested |
| 0.2.1.0 | 2018-03-08 21:40 UTC | andrewthad | 3 revisions | +67/−9 lines, 5 filesdep +semigroupsdep −exceptionsdep ~basePVP: major bump suggested |
| 0.2.0.0 | 2017-12-09 17:36 UTC | andrewthad | 1 revisions | +659/−463 lines, 5 filesdep −monad-controldep −resourcetdep −timedep ~basedep ~mmorphdep ~transformersnew-uploader |
| 0.1.4.5 | 2017-01-17 08:10 UTC | MichaelThompson | 1 revisions | +3/−3 lines, 1 files |
| 0.1.4.4 | 2017-01-17 08:05 UTC | MichaelThompson | 1 revisions | +221/−205 lines, 3 filesdep +containers |
| 0.1.4.3 | 2016-06-12 11:02 UTC | MichaelThompson | 1 revisions | +4259/−4202 lines, 9 filessetup-changed |
| 0.1.4.2 | 2016-06-01 14:33 UTC | MichaelThompson | 1 revisions | +179/−123 lines, 4 filesdep +monad-controldep ~basedep ~mmorphdep ~transformers |
| 0.1.4.1 | 2016-04-08 00:51 UTC | MichaelThompson | +555/−303 lines, 5 filesdep +ghc-primdep −bytestringdep −containersdep ~exceptionsdep ~resourcetdep ~transformers | |
| 0.1.4.0 | 2015-12-26 22:45 UTC | MichaelThompson | +541/−184 lines, 4 files | |
| 0.1.3.4 | 2015-12-06 00:36 UTC | MichaelThompson | +3/−2 lines, 2 files | |
| 0.1.3.3 | 2015-12-03 18:01 UTC | MichaelThompson | +18/−9 lines, 2 files | |
| 0.1.3.2 | 2015-12-03 17:35 UTC | MichaelThompson | +17/−11 lines, 1 files | |
| 0.1.3.1 | 2015-12-03 17:18 UTC | MichaelThompson | +4/−4 lines, 1 filesPVP ok | |
| 0.1.3.0 | 2015-12-03 17:08 UTC | MichaelThompson | +2774/−2028 lines, 4 filesdep +containersdep +exceptionsdep +resourcet | |
| 0.1.2.2 | 2015-11-03 04:05 UTC | MichaelThompson | +272/−155 lines, 4 files | |
| 0.1.2.0 | 2015-10-20 22:33 UTC | MichaelThompson | +474/−217 lines, 5 filesdep −random | |
| 0.1.1.1 | 2015-10-06 03:07 UTC | MichaelThompson | +324/−72 lines, 2 filesdep +time | |
| 0.1.1.0 | 2015-10-05 00:53 UTC | MichaelThompson | +92/−44 lines, 5 filesdep +random | |
| 0.1.0.20 | 2015-09-19 19:13 UTC | MichaelThompson | +211/−350 lines, 2 files | |
| 0.1.0.19 | 2015-09-19 18:30 UTC | MichaelThompson | +81/−36 lines, 2 files | |
| 0.1.0.18 | 2015-09-19 15:05 UTC | MichaelThompson | +271/−59 lines, 3 filesdep +bytestring | |
| 0.1.0.17 | 2015-09-13 16:08 UTC | MichaelThompson | +107/−8 lines, 2 files | |
| 0.1.0.16 | 2015-09-10 01:10 UTC | MichaelThompson | 1 revisions | +142/−72 lines, 4 filesdep ~basedep ~transformers |
| 0.1.0.15 | 2015-08-31 03:50 UTC | MichaelThompson | +14/−13 lines, 1 filesPVP ok | |
| 0.1.0.14 | 2015-08-31 03:44 UTC | MichaelThompson | +3/−3 lines, 1 files | |
| 0.1.0.13 | 2015-08-31 03:37 UTC | MichaelThompson | +32/−11 lines, 1 files | |
| 0.1.0.12 | 2015-08-30 19:10 UTC | MichaelThompson | +60/−32 lines, 4 files | |
| 0.1.0.11 | 2015-08-27 15:07 UTC | MichaelThompson | +5/−2 lines, 1 files | |
| 0.1.0.10 | 2015-08-27 13:48 UTC | MichaelThompson | +14/−15 lines, 4 filesdep ~base | |
| 0.1.0.9 | 2015-08-27 06:06 UTC | MichaelThompson | 1 revisions | +33/−4 lines, 4 files |
| 0.1.0.8 | 2015-08-26 15:21 UTC | MichaelThompson | 1 revisions | +201/−41 lines, 4 files |
| 0.1.0.7 | 2015-08-22 16:13 UTC | MichaelThompson | 1 revisions | +351/−118 lines, 4 filesdep −ghc-prim |
| 0.1.0.6 | 2015-08-17 22:11 UTC | MichaelThompson | 1 revisions | +106/−56 lines, 3 files |
| 0.1.0.5 | 2015-08-17 04:44 UTC | MichaelThompson | 1 revisions | +28/−14 lines, 2 files |
| 0.1.0.4 | 2015-08-17 04:16 UTC | MichaelThompson | 1 revisions | +304/−65 lines, 4 files |
| 0.1.0.3 | 2015-08-16 01:44 UTC | MichaelThompson | 1 revisions | +153/−30 lines, 4 files |
| 0.1.0.1 | 2015-08-14 19:19 UTC | MichaelThompson | 1 revisions | +76/−7 lines, 3 files |
| 0.1.0.0 | 2015-08-14 18:31 UTC | MichaelThompson | 1 revisions | +1308/−0 lines, 6 filesdep +basedep +ghc-primdep +mmorphsetup-changed |
Dependencies of streaming-0.2.4.0
QuickCheck >=2.13 2.18.0.0 → 2.19.0.0
| 2026-09-16 11:18 UTC | 2.19.0.0 | +67/−41 lines, 10 filesdep +OneTuplePVP ok |
| 2026-02-26 12:42 UTC | 2.18.0.0 | +826/−542 lines, 23 filesPVP ok |
| 2025-10-13 12:40 UTC | 2.17.1.0 | +18/−8 lines, 4 filesdep ~randomPVP: major bump suggested |
| 2025-10-07 12:26 UTC | 2.17.0.0 | +667/−129 lines, 14 filesdep +data-array-bytedep +hintdep +splitdep −ghc-primdep −old-localedep −old-timedep ~basedep ~randomdep ~template-haskellPVP ok |
| 2025-06-17 07:53 UTC | 2.16.0.0 | +477/−86 lines, 15 filesdep ~basenew-uploaderPVP ok |
showing 5 of 66 versions
base >=4.8 && <5 4.22.0.0 → 4.22.1.0
| 2026-12-01 12:38 UTC | 4.22.1.0 | +388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested |
| 2025-12-19 11:52 UTC | 4.22.0.0 | +886/−215 lines, 28 filesdep ~ghc-internalPVP ok |
| 2026-03-27 12:26 UTC | 4.21.2.0 | +10/−3 lines, 4 filesdep ~ghc-internalPVP ok |
| 2025-12-27 10:31 UTC | 4.21.1.0 | +17/−5 lines, 4 filesdep ~ghc-internalPVP ok |
| 2024-12-16 09:24 UTC | 4.21.0.0 | +1170/−396 lines, 39 filesdep ~ghc-internalPVP ok |
showing 5 of 61 versions
containers >=0 0.8 → 0.8.1
| 2026-10-04 06:08 UTC | 0.8.1 | +8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested |
| 2025-03-01 13:03 UTC | 0.8 | +8447/−7031 lines, 37 filesnew-uploaderPVP ok |
| 2023-09-27 12:15 UTC | 0.7 | +76/−33 lines, 3 filesPVP ok |
| 2023-09-28 04:21 UTC | 0.6.8 | +644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested |
| 2023-02-01 03:11 UTC | 0.6.7 | +783/−229 lines, 20 filesPVP: major bump suggested |
showing 5 of 43 versions
fail >=4.9 && <4.10 (empty) → 4.9.0.0
| 2016-01-21 15:11 UTC | 4.9.0.0 | +144/−0 lines, 4 filesdep +basesetup-changed |
ghc-prim >=0 0.12.0 → 0.13.0
| 2024-12-16 09:29 UTC | 0.13.0 | +95/−12 lines, 6 filesPVP ok |
| 2025-05-03 11:48 UTC | 0.12.0 | +5108/−1582 lines, 15 filesnew-uploaderPVP ok |
| 2023-10-10 00:24 UTC | 0.11.0 | +770/−234 lines, 9 filesPVP ok |
| 2023-03-28 14:22 UTC | 0.10.0 | +487/−297 lines, 16 filesPVP ok |
| 2022-08-07 20:08 UTC | 0.9.0 | +2921/−2018 lines, 14 filesPVP ok |
showing 5 of 15 versions
hspec >=2.7 2.11.17 → 2.11.18
| 2026-10-01 14:14 UTC | 2.11.18 | +7/−4 lines, 3 filesdep ~hspec-coredep ~hspec-discoverPVP ok |
| 2026-03-04 18:01 UTC | 2.11.17 | +11/−19 lines, 6 filesdep ~hspec-coredep ~hspec-discoverPVP ok |
| 2025-12-12 14:07 UTC | 2.11.16 | +25/−7 lines, 5 filesdep ~hspec-coredep ~hspec-discoverPVP: major bump suggested |
| 2025-12-08 03:04 UTC | 2.11.15 | +8/−5 lines, 3 filesdep ~hspec-coredep ~hspec-discoverPVP ok |
| 2025-09-30 14:32 UTC | 2.11.14 | +9/−7 lines, 4 filesdep ~hspec-coredep ~hspec-discoverPVP: major bump suggested |
showing 5 of 171 versions
mmorph >=1.0 && <1.3 1.2.1 → 1.2.2
| 2026-01-09 03:36 UTC | 1.2.2 | +7/−4 lines, 2 filesdep ~basedep ~transformers-compatPVP ok |
| 2025-06-08 03:52 UTC | 1.2.1 | +24/−11 lines, 4 filesdep ~transformers-compatPVP: major bump suggested |
| 2021-07-16 23:14 UTC | 1.2.0 | +7/−23 lines, 3 filesdep ~mtldep ~transformersdep ~transformers-compatPVP ok |
| 2021-02-17 00:30 UTC | 1.1.5 | +34/−15 lines, 4 filesdep ~basePVP ok |
| 2021-01-31 19:49 UTC | 1.1.4 | +32/−76 lines, 3 filesdep +faildep ~basePVP: major bump suggested |
showing 5 of 19 versions
mtl >=2.1 && <2.4 2.3.1 → 2.3.2
| 2025-12-08 04:58 UTC | 2.3.2 | +112/−21 lines, 12 filesdep ~basenew-uploaderPVP: major bump suggested |
| 2022-10-31 21:28 UTC | 2.3.1 | +188/−33 lines, 8 filesdep ~basePVP: major bump suggested |
| 2022-05-07 20:34 UTC | 2.3 | +1284/−520 lines, 29 filesdep ~basedep ~transformersnew-uploaderPVP ok |
| 2018-02-24 22:15 UTC | 2.2.2 | +152/−36 lines, 14 filesdep ~basePVP: major bump suggested |
| 2014-06-02 02:22 UTC | 2.2.1 | +179/−4 lines, 8 filesdep ~basedep ~transformersPVP: major bump suggested |
showing 5 of 20 versions
semigroups >=0.18 && <0.20 0.19.2 → 0.20.1 newer than bounds
| 2026-01-10 20:32 UTC | 0.20.1 newer than bounds | +29/−2103 lines, 6 filesdep −binarydep −bytestringdep −bytestring-builderdep ~basePVP: major bump suggested |
| 2021-11-16 00:07 UTC | 0.20 newer than bounds | +9/−27 lines, 3 filesdep ~hashablePVP ok |
| 2021-08-30 11:23 UTC | 0.19.2 | +45/−203 lines, 6 filesdep ~hashablePVP ok |
| 2019-08-27 13:06 UTC | 0.19.1 | +100/−60 lines, 5 filesdep ~hashabledep ~transformersPVP ok |
| 2019-05-10 13:57 UTC | 0.19 | +217/−167 lines, 5 filesdep +template-haskelldep ~hashablePVP ok |
showing 5 of 65 versions
transformers >=0.4 && <0.7 0.6.2.0 → 0.6.3.0
| 2026-01-12 12:42 UTC | 0.6.3.0 | +28/−1 lines, 4 filesPVP: major bump suggested |
| 2025-04-06 22:39 UTC | 0.6.2.0 | +41/−42 lines, 8 filesdep ~ghc-primPVP: major bump suggested |
| 2024-09-25 11:37 UTC | 0.6.1.2 | +70/−21 lines, 19 filesPVP: minor bump suggested |
| 2023-08-01 19:13 UTC | 0.6.1.1 | +281/−42 lines, 11 filesPVP ok |
| 2023-02-04 08:15 UTC | 0.6.1.0 | +64/−4 lines, 8 filesPVP ok |
showing 5 of 42 versions
transformers-base <0.5 0.4.6 → 0.4.6.1
| 2026-03-09 18:21 UTC | 0.4.6.1 | +11/−5 lines, 3 filesPVP: major bump suggested |
| 2021-08-01 21:25 UTC | 0.4.6 | +21/−5 lines, 2 filesdep ~transformersPVP: major bump suggested |
| 2018-03-31 21:50 UTC | 0.4.5.2 | +2/−8 lines, 2 filesdep ~transformers-compatPVP ok |
| 2018-03-31 19:33 UTC | 0.4.5.1 | +7/−1 lines, 2 filesPVP ok |
| 2018-03-31 16:40 UTC | 0.4.5 | +39/−16 lines, 3 filesdep +base-orphansdep ~basedep ~transformers-compatPVP: major bump suggested |
showing 5 of 14 versions
Reverse dependencies
94 packages depend on streaming