scala - 我有一个带有隐式参数的函数。如何使用某个类的实例的隐式参数隐式传递参数?
问题描述
这是功能:
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
功能
那么,我怎样才能将它传递handler
给repo
它呢?
注意:如果类SomeService
继承自ElasticSearchRepositoryWrapper
它找到它。
解决方案
我不确定 的第一个参数是什么execute
。看起来它想要一些t
,但你正在传递一个块(不是说它一定是错误的,但有点奇怪)。但是,假设这确实是您想要的并且repo.handler
可以访问,您可以像这样传递它:
repo.client.execute(repo.delete(something))(ec, implicitly, repo.handler, implicitly)
推荐阅读
- excel - 复制工作表 1 中的范围并粘贴到循环中下一张工作表的下一个空行
- python - 从子目录和子目录中导入时如何解决冲突的导入要求?
- azure-devops - 与本地机器相比,管道构建后packages文件夹的内容不同
- dom-manipulation - 谁能告诉我为什么错误在我的代码中显示它是基本的 addeventlistener 格式
- amazon-web-services - 如何在 AWS::ElasticBeanstalk::Environment 中设置环境变量?
- swift - UIViewRepresentable 视图如何获取在父级设置的环境属性
- sql - 根据用户条件执行部分 SQL 查询
- android - 如何使用 docusign mobile-android-sdk 以编程方式将只读字段添加到 Android 上的模板?
- c++ - 没有按预期工作的简单特征(MSVC 与 gcc 和 clang)以及如何修复它
- slack - 是否可以使用新传入的 webhook 设置 icon_emoji ?