我有一个很难得到一个 implicit class
对于一个 akka.stream.scaladsl.SubFlow
编译。
我的测试码:
val subFlow = Source(List("1", "2", "3"))
.groupBy(1, f)
val richSubFlow = new SideEffectfulSubFlowOps(subFlow)
val got = richSubFlow
.withSideEffect((elem: String) => recordedItems.add(elem))
.mergeSubstreams
.to(Sink.seq)
/* In the end I would like to write it like this:
val got = Source(List("1", "2", "3"))
.groupBy(1, f)
.withSideEffect((elem: String) => recordedItems.add(elem))
.mergeSubstreams
.to(Sink.seq)
*/
隐类的我有这么远。
implicit class SideEffectfulSubFlowOps[+Out, +Mat, FOps <: FlowOps[Out, Mat], C](val enrichedSubFlow: SubFlow[Out, Mat, FOps#Repr, C]) extends AnyVal {
def withSideEffect(f: Out => Unit): enrichedSubFlow.Repr[Out] = {
enrichedSubFlow.map { o =>
f(o)
o
}
}
}
不幸的是,我无法找出适当的通用类型来定义的隐含类。
编译错误:
[error] SubFlowExtensionsSpec.scala:21:43: type mismatch;
[error] found : akka.stream.scaladsl.SubFlow[String,akka.NotUsed,[+O]akka.stream.scaladsl.Source[O,akka.NotUsed],akka.stream.scaladsl.RunnableGraph[akka.NotUsed]]
[error] required: akka.stream.scaladsl.SubFlow[?,?,?#Repr,?]
[error] val x = new SideEffectfulSubFlowOps(subFlow)
看定义的子流: trait SubFlow[+Out, +Mat, +F[+_], C] extends FlowOps[Out, Mat]
我不明白我是如何需要确定的一般类型对我隐类然后将它们用于类型 F
和 C
的 SubFlow
.
argument expression's type is not compatible with formal parameter type