[英]Akka: Transforming the Input of a Sink with a Materialized Value
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. 我有一个Sink[String, Mat]
器: Sink[String, Mat]
并想通过映射每个元素将其转换为Sink[Int, Mat]
器: Sink[Int, Mat]
: num: Int => ("num" + num): String
并保持原始物化类型和值。
If Mat
was Unit
, then it's easy: 如果Mat
是Unit
,那么很简单:
def transformSink(sink: Sink[String, Unit]): Sink[Int, Unit] =
Flow[Int].map("num" + _).to(sink)
But what about transforming a sink for any Mat
? 但是,如何为任何Mat
转换接收器呢?
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] = ???
I think toMat
is what you are looking for. 我认为toMat
是您想要的。 See if this works for you: 看看这是否适合您:
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] =
Flow[Int].map("num" + _).toMat(sink)(Keep.right)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.