Given simple source/sink/flows:
val source: Source[Int, NotUsed] = Source(1 to 5)
val sink: Sink[Any, Future[Done]] = Sink.foreach(println)
val intDoublerFlow: Flow[Int, Int, NotUsed] = Flow.fromFunction[Int, Int](i => i * 2)
I can combine a Source[T, M]
with Flow[T, T2, M2]
and get a Source[T2, M2]
with the via
method:
val sourceWithFlow: Source[Int, NotUsed] = source.via(intDoublerFlow)
How can I do the analogous operation and combine a Flow[T, T2, M]
with Sink[T2, M2]
to get Sink[T, M2]
val sinkWithFlow: Sink[Int, Future[Done]] = ???
Sink[Any, Future[Done]
is also aSink[Int, Future[Done]
already, sinceSink
is contravariant over its first type parameter. – Michael Zajacflow.to(sink)
orflow.toMat(sink)(Keep.right)
– clay