我有一个带有隐式参数的函数。如何使用某些 class 实例的隐式参数隐式传递参数?
I have a function which takes an implicit parameter. How can I pass the parameter implicitly using implicit parameters of an instance of some class?
这是函数:
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)}
我有一个 class ElasticSearchRepositoryWrapper
继承自某个地方(我无法从哪里找到)handler
变量。
我有一个 class 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
函数
那么,如何将 handler
从 repo
传递给它呢?
注意:如果 class SomeService
继承自 ElasticSearchRepositoryWrapper
它会找到它。
我不确定execute
的第一个参数是什么。看起来它想要一些 t
,但你传递的是一个块(并不是说它一定是错误的,但有点奇怪)。但是,假设这确实是你想要的,并且 repo.handler
是可访问的,你可以像这样传递它:
repo.client.execute(repo.delete(something))(ec, implicitly, repo.handler, implicitly)
这是函数:
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)}
我有一个 class ElasticSearchRepositoryWrapper
继承自某个地方(我无法从哪里找到)handler
变量。
我有一个 class 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
函数
那么,如何将 handler
从 repo
传递给它呢?
注意:如果 class SomeService
继承自 ElasticSearchRepositoryWrapper
它会找到它。
我不确定execute
的第一个参数是什么。看起来它想要一些 t
,但你传递的是一个块(并不是说它一定是错误的,但有点奇怪)。但是,假设这确实是你想要的,并且 repo.handler
是可访问的,你可以像这样传递它:
repo.client.execute(repo.delete(something))(ec, implicitly, repo.handler, implicitly)