To summarize:
fs2 is a library for describing functional streams.
Streams can be finite or infinite: fs2 doesn’t make a distinction between them.
A stream is composed of operators such as
take
andrepeat
.Instead of thinking of streams as infinite lists, it’s better to think of them as programs: a series of steps that is run when we demand a value from them.
fs2 has a notional machine associated with it: we can think of streams in terms of the pull model.
Each operator can be described in terms of
pull
,output
anddone
steps.We can describe a composition of operators such as
kittens.take(3).repeat
by chaining their pull and output steps.We can even draw a pull diagram depicting all the steps in a stream.
Congratulations on making it this far!
Understanding the pull model is a lot of work, but is a worthy investment. You’ll be able to make sense of many more operators in the fs2 ecosystem, not just the ones for manipulating pure infinite streams.
In fact, you might even be ready to dive under the surface of fs2 and start writing your own operators.