【问题标题】:Scala diverging implicit expansion for cats.effect.Timer when using monix TaskAppScala 在使用 monix TaskApp 时为cats.effect.Timer 发散隐式扩展
【发布时间】:2021-09-23 06:54:04
【问题描述】:

CE 2.x。莫尼克斯 3.4。第1行编译,第2行给出编译错误:

cats.kernel.Order[A] 类型的发散隐式扩展 从对象 Eq 中的方法 catsKernelOrderForFunction0 开始 Stream.sleep_(5.seconds).compile.drain.as(ExitCode.Success) // 2

import cats.effect.{ExitCode, Timer}
import fs2.Stream
import monix.eval.{Task, TaskApp}
import scala.concurrent.duration.DurationInt


object ImplicitsFreeze extends TaskApp {

  def run(args: List[String]): Task[ExitCode] = {
    Stream.sleep_(5.seconds)(implicitly[Timer[Task]]).compile.drain.as(ExitCode.Success)  // 1
//    Stream.sleep_(5.seconds).compile.drain.as(ExitCode.Success) // 2
  }

}

【问题讨论】:

    标签: scala implicit monix


    【解决方案1】:

    添加效果类型的注解解决了问题

    Stream.sleep_[Task](5.seconds).compile.drain.as(ExitCode.Success) // 2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-18
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 1970-01-01
      • 2015-03-30
      相关资源
      最近更新 更多