我有一个采用隐式参数的函数。如何使用某些类的实例的隐式参数隐式传递参数?

问题描述 投票:0回答:1

这是功能:

def execute[T, U, F[_]](t: T)(implicit
                                executor: Executor[F],
                                functor: Functor[F],
                                handler: Handler[T, U],
                                manifest: Manifest[U]): F[Response[U]] = {(do something)}

我有一个ElasticSearchRepositoryWrapper类,它从某个地方(我从哪里找不到)handler变量继承。我有一个类repo = ElasticSearchRepositoryWrapper(client, config, configName)的实例我想这样做:

class SomeService(val config: Config,
                             val configName: String = "products",
                             val client: ElasticClient)
                            (implicit val ec: ExecutionContext)
{
    repo = ElasticSearchRepositoryWrapper(client, config, configName)
    repo.client.execute {
      repo.delete(something)
    }
}

但说,No implicits found for parameter handler: Handler[..., ...]用于execute功能因此,如何将handlerrepo传递给它?注意:如果类SomeServiceElasticSearchRepositoryWrapper继承,则会找到它。

scala inheritance parameter-passing implicit
1个回答
0
投票
我不确定execute的第一个参数是什么。似乎需要一些t,但您正在传递一个块(并不是说它一定是错误的,而是有点奇怪)。但是,假设这确实是您想要的,并且可以访问repo.handler,则可以像这样传递它:

repo.client.execute(repo.delete(something))(ec, implicitly, repo.handler, implicitly)

© www.soinside.com 2019 - 2024. All rights reserved.