You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: same kind as below
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 ()
Output
no implicit argument of type List[Int] was found for parameter e of method implicitly in object Predef
Expectation
For comprehensions to work cleanly with givens, whether they are defined by a <- or a =.
Would be really great if this worked as implicits and composing dependencies in for comprehensions is fundamental in the tagless final style of coding. Basically the initial part of the application, defining the components makes use of this.
Workaround
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")
givenList[Int] =List(1, 2, 3)
p <-Option("dummy")
b = implicitly[List[Int]] // worksyield ()
The text was updated successfully, but these errors were encountered:
Compiler version
3.1.1, 3.1.2
Minimized code
How do you fetch an implicit value in a for comprehension, when its type is parameterized?
Output
Expectation
For comprehensions to work cleanly with givens, whether they are defined by a
<-
or a=
.Would be really great if this worked as implicits and composing dependencies in for comprehensions is fundamental in the tagless final style of coding. Basically the initial part of the application, defining the components makes use of this.
Workaround
But if I insert a dummy line in between the declaration and the usage, it works:
The text was updated successfully, but these errors were encountered: