Scala can't cast types Publisher[Publisher[_ <: T]] cannot be applied to (Flux[Flux[String]]

时间:2019-01-07 13:04:02

标签: scala project-reactor

I implemented simple streams in Scala with Project Reactor stream implementation.

  val iterators: Iterable[Flux[String]] = for (i <- 0 to 4000) yield Flux.interval(5 seconds).map(_.toString)
  val publishers: Flux[Flux[String]] = Flux.just(iterators).flatMapIterable(identity)
  Flux.merge(publishers, 1)

Tried to compile that code but got error

Error:(156, 8) overloaded method value merge with alternatives:
  [I](prefetch: Int, sources: org.reactivestreams.Publisher[_ <: I]*)reactor.core.scala.publisher.Flux[I] <and>
  [I](sources: org.reactivestreams.Publisher[_ <: I]*)reactor.core.scala.publisher.Flux[I] <and>
  [T](source: org.reactivestreams.Publisher[org.reactivestreams.Publisher[_ <: T]], concurrency: Int)reactor.core.scala.publisher.Flux[T]
 cannot be applied to (reactor.core.scala.publisher.Flux[reactor.core.scala.publisher.Flux[String]], Int)

Why scala can't cast these types ?

Flux.merge(publishers) works well but when I pass integer argument, scala compiler fails with error.

1 个答案:

答案 0 :(得分:0)

如果您使用的是react-scala-extensions,则该错误将在0.4.8中修复