5

我正在尝试编译流,但不知何故Compiler不在范围内,需要什么上下文绑定才能将其纳入范围?

import cats.Monad

def compilingStream[F[_]: Monad]: F[List[Int]] = {
  val stream: fs2.Stream[F, Int] = fs2.Stream.emit(1).covary[F]
  stream.head.compile.toList
}


error: could not find implicit value for parameter compiler: fs2.Stream.Compiler[[x]F[x],G]
         stream.head.compile.toList
                     ^

4

1 回答 1

7

Fs2Stream#compile现在需要一个Sync[F](见这个):

  import cats.effect.Sync

  def compilingStream[F[_]: Sync]: F[List[Int]] = {
    val stream: fs2.Stream[F, Int] = fs2.Stream.emit(1).covary[F]
    stream.head.compile.toList
  }

这是由库维护者传达的:

fs2 Stream#compile 现在需要 Sync[F]。即使在完全纯净的溪流上。因为资源管理。伤心。熊猫。

丹尼尔·斯皮瓦克

于 2019-05-27T16:07:19.367 回答