Can someone explain clearly what are the difference between those 4 methods ? When is it more appropriate to use each one ? Also generally speaking what is the name of this Group of method? Are there more method that does the same job ? A link to the scaladoc could also help.
-D-
All these methods are necessary to join two streams into one stream. For example, you can create a
Source
out of aSource
and aFlow
, or you can create aSink
out of aFlow
and aSink
, or you can create aFlow
out of twoFlow
s.For this, there are two basic operations,
to
andvia
. The former allows one to connect either aSource
or aFlow
to aSink
, while the latter allows to connect aSource
or aFlow
to aFlow
:For the reference, a runnable graph is a fully connected reactive stream which is ready to be materialized and executed.
*Mat
versions of various operations allow one to specify how materialized values of streams included in the operation should be combined. As you may know, each stream has a materialized value which can be obtained when the stream is materialized. For example,Source.queue
yields a queue object which can be used by another part of your program to emit elements into the running stream.By default
to
andvia
on sources and flows only keeps the materialized value of the stream it is called on, ignoring the materialized value of its argument:Sometimes, however, you need to keep both materialized values or to combined them somehow. That's when
Mat
variants of methods are needed. They allow you to specify the combining function which takes materialized values of both operands and returns a materialized value of the combined stream:For example, to keep both materialized values, you can use
Keep.both
method, or if you only need the mat.value of the "right" operand, you can useKeep.right
method: