stojan
09/30/2020, 7:15 PMsimon.vergauwen
10/01/2020, 7:13 AMF
. Therefore it's a lot simpler in design since it uses suspend
all over, instead of making the distincinction between Pure
, Infallible
etc
Both Flow
and Stream
provide a pull based mechanism for streaming, but Stream
splits itself in a Pull
API and a Stream
API.
Flow
offers APIs where you bridge different `Flow`'s to build combinators by using a suspend
back-pressured system. (Typically you collect
and re-emit on a different Flow
).
In contrast Stream
offers a functional API where you can inspect/pull elements and the state of the Stream
, but the focus on building custom operators is low since it aims to be a fully featured toolbox like RxJava where all operators live inside the library and user rely on composition.
Therefore Stream
has a mechanism for safely composing streaming resource, which is one of the strongest features of FS2. You can open a resource with Stream.bracket
or Stream.resource
and it automatically extends/closes the scope/resource depending on which compositonal operators are used.
It also works Chunk
based so it's a Stream
that has Array
of elements at its leaves instead of single elements, and it allows you to work in constant space on those `Chunk`s in its API.
RxJava
is a completely different beast on its own since its push
based and also single element.
Not sure if that fully answers your question so be sure to ask follow up questions if you have any!gildor
10/01/2020, 7:19 AMBut why Flow is pull based?is a completely different beast on its own since itsRxJava
based and also single element.push
simon.vergauwen
10/01/2020, 7:22 AMflow {
emit(1)
// Never reaches here until 1 is consumed
emit(2)
}
simon.vergauwen
10/01/2020, 7:25 AMsimon.vergauwen
10/01/2020, 7:26 AMmore desiredTake that with a grain of salt, since some people might find push based more desired 😅 From the perspective of functional programming it's definitely more desired.
gildor
10/01/2020, 7:28 AMgildor
10/01/2020, 7:28 AMstojan
10/01/2020, 7:31 AMsimon.vergauwen
10/01/2020, 7:37 AMIO.bracket
or Resource
with IO
.simon.vergauwen
10/01/2020, 7:38 AMstojan
10/01/2020, 7:50 AM