Eu sunt având un timp de greu pentru a obține o implicit class
pentru o akka.stream.scaladsl.SubFlow
pentru a compila.
Testul meu de cod:
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 clasa I până în prezent.
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
}
}
}
Din păcate, eu nu pot da seama corespunzătoare tipurilor generice de a defini pentru implicite de clasă.
Compilatorul de eroare:
[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)
Se uită la definiția subflow: trait SubFlow[+Out, +Mat, +F[+_], C] extends FlowOps[Out, Mat]
Nu inteleg de ce am nevoie pentru a defini tipuri generice pe al meu implicit clasa care sunt apoi utilizate pentru tip F
și C
de SubFlow
.
argument expression's type is not compatible with formal parameter type