Akka:使用物化值转换接收器的输入

时间:2015-07-29 09:40:28

标签: scala akka akka-stream

我有一个接收器:Sink[String, Mat]并想通过映射每个元素Sink[Int, Mat]并将其转换为接收器num: Int => ("num" + num): String并保留原始的物化类型和值。

如果MatUnit,则很容易:

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] = ???

1 个答案:

答案 0 :(得分:2)

我认为toMat正是您所寻找的。看看这是否适合你:

def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] =
  Flow[Int].map("num" + _).toMat(sink)(Keep.right)
}