0

我有一个接收器: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] = ???
4

1 回答 1

2

我想toMat这就是你要找的。看看这是否适合你:

def transformSink[Mat](sink: Sink[String, Mat]): Sink[Int, Mat] =
  Flow[Int].map("num" + _).toMat(sink)(Keep.right)
}
于 2015-07-29T11:47:27.553 回答