在A s scala 3中获得一个隐式参数化类型
Scala 3语法问题。 我觉得围绕此内容还没有足够的文档。
当该类型被参数化时,如何在A for中获取隐式值?
for
o <- Option("line just to make for comprehension start")
given Int = 2
a = implicitly[Int] // error: no implicit argument of type Int was found for parameter e of method implicitly in object Predef
given List[Int] = List(1, 2, 3)
b = implicitly[List[Int]] // error: no implicit argument of type List[Int] was found for parameter e of method implicitly in object Predef
yield ()
编辑:
,但是如果我在声明和用法之间插入虚拟行,则可以工作:
for
o <- Option("line just to make for comprehension start")
given List[Int] = List(1, 2, 3)
p <- Option("dummy")
b = implicitly[List[Int]] // works
yield ()
A Scala 3 syntax question here.
I feel like there's not enough documentation around this yet.
How do you fetch an implicit value in a for comprehension, when its type is parameterized?
for
o <- Option("line just to make for comprehension start")
given Int = 2
a = implicitly[Int] // error: no implicit argument of type Int was found for parameter e of method implicitly in object Predef
given List[Int] = List(1, 2, 3)
b = implicitly[List[Int]] // error: no implicit argument of type List[Int] was found for parameter e of method implicitly in object Predef
yield ()
Edit:
But if I insert a dummy line in between the declaration and the usage, it works:
for
o <- Option("line just to make for comprehension start")
given List[Int] = List(1, 2, 3)
p <- Option("dummy")
b = implicitly[List[Int]] // works
yield ()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论