我有一个接收器:Sink[String, Mat]
并想通过映射每个元素Sink[Int, Mat]
并将其转换为接收器num: Int => ("num" + num): String
并保留原始的物化类型和值。
如果Mat
为Unit
,则很容易:
def transformSink(sink: Sink[String, Unit]): Sink[Int, Unit] =
Flow[Int].map("num" + _).to(sink)
但是为任何Mat
转换接收器怎么样?
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] = ???
答案 0 :(得分:2)
我认为toMat
正是您所寻找的。看看这是否适合你:
def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] =
Flow[Int].map("num" + _).toMat(sink)(Keep.right)
}