** Adapted from an answer in the FS2 gitter channel by Fabio Labella: https://gitter.im/functional-streams-for-scala/fs2?at=5e962ebb6823cb38acd12ebd
What is Stream.compile
and what does it do? Is it actually compiling something? Optimizing the streaming somehow?
At its core, Stream[I, O].compile
is nothing more than a namespace for related methods that return the same type wrapper, I
. It's not compiling anything or doing any optimization. For example, all the methods on (s: Stream[IO, Int]).compile
generally have the return type IO
.
In FP there is a technique of design through algebras (speaking here in the most general sense, even more general than tagless final) and it basically works like this:
- you have some type, for example
Option
- some introduction forms (ways of getting "into" the algebra, e.g.,
Option.empty
,Option.some
; this is often referred to as "lifting" into a type)