transparent inline apply: how to achieve the apply syntax sugar? #19994
Answered
by
nicolasstucki
TomasMikula
asked this question in
Metaprogramming
-
Given a import scala.quoted.*
class Foo[A]:
transparent inline def apply =
${ Foo.go[A] }
object Foo:
def go[A](using Quotes, Type[A]) =
Type.of[A] match
case '[Int] => '{ (n: Int) => n+1 }
case _ => '{ (n: Nothing) => n } I'd like to be able to call @main
def main =
val foo = Foo[Int]
foo.apply(1) // OK
foo(1) // Error: method apply in class Foo does not take parameters Is it achievable (possibly using some inline given conversions)? |
Beta Was this translation helpful? Give feedback.
Answered by
nicolasstucki
Mar 21, 2024
Replies: 2 comments 1 reply
-
I am also looking for something like this for ops-mirror |
Beta Was this translation helpful? Give feedback.
0 replies
-
A workaround for this is - transparent inline def apply =
+ transparent inline def apply(using inline di: DummyImplicit) = |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
TomasMikula
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A workaround for this is