输入别名和隐式值解析

时间:2018-07-20 06:55:34

标签: scala scala-cats monix

我认为这很容易,但是我遇到了一个问题,即找不到Flatix或Monix Task的函子。 我使用“类型别名”来简化长类型签名,但是在for-compression中,我收到“找不到隐式值”错误。 如果我删除类型别名,那么它将起作用,因为Monix支持cats。 有人会建议如何告诉编译器TaskEither是Monix Task,并且可以只使用Monix Task提供的cats实例。 输入别名:

type TaskEither[A] = Task[Either[Erratum, A]]

发生错误的方法: 注意:getBotForUser和processBotDetails都包裹在类似于findCreateBot方法的Kleisli中

def findCreateBot(msg: Routing): Kleisli[TaskEither, DBRepo[MySQLProfile, ServiceConfig[Config]], ActorRef] ={
    import Task._
    for {
      bot <- XmppRepository[MySQLProfile, ServiceConfig[Config]].getBotForUser(msg.routingHeader.to.userID)
      botRef <- processBotDetails(bot)
    } yield botRef
  }

错误消息:

XMPPGateway.scala:61:14: could not find implicit value for parameter F: cats.Functor[MyTypes.TaskEither]
[error]       botRef <- processBotDetails(bot)
[error]  

        ^

错误消息:

XMPPGateway.scala:60:11: could not find implicit value for parameter F: cats.FlatMap[MyTypes.TaskEither]
[error]       bot <- XmppRepository[MySQLProfile, ServiceConfig[Config]].getBotForUser(msg.routingHeader.to.userID)
[error]  

     ^

1 个答案:

答案 0 :(得分:0)

如果您也使用cats,则必须导入cats.data._ 导入cats.implicits ._