Reputation: 879
I have a sink: Sink[String, Mat]
and want to transform it into the sink: Sink[Int, Mat]
by mapping each element: num: Int => ("num" + num): String
and keeping the original materialized type and value.
If Mat
was Unit
, then it's easy:
def transformSink(sink: Sink[String, Unit]): Sink[Int, Unit] =
Flow[Int].map("num" + _).to(sink)
But what about transforming a sink for any Mat
?
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] = ???
Upvotes: 0
Views: 576
Reputation: 35443
I think toMat
is what you are looking for. See if this works for you:
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] =
Flow[Int].map("num" + _).toMat(sink)(Keep.right)
}
Upvotes: 2