我正在尝试编译流,但不知何故Compiler
不在范围内,需要什么上下文绑定(bind)才能将其纳入范围?
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
^
最佳答案
FS2 Stream#compile
现在需要 Sync[F]
(见 this):
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 now requires a Sync[F]. Even on completely pure streams. Because of resource management. Sad. Panda.
Daniel Spiewak
关于scala - Fs2 Stream.Compiler 未找到(找不到隐含值 Compiler[[x]F[x],G]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329032/