-
Notifications
You must be signed in to change notification settings - Fork 1.1k
transparent inline apply: how to achieve the apply syntax sugar? #19994
Answered
by
nicolasstucki
TomasMikula
asked this question in
Metaprogramming
-
Given a transparent inline def apply
that generates a function,
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 foo(x)
instead of foo.apply(x)
:
@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.
All reactions
Answered by
nicolasstucki
Mar 21, 2024
A workaround for this is
- transparent inline def apply = + transparent inline def apply(using inline di: DummyImplicit) =
Replies: 2 comments 1 reply
-
I am also looking for something like this for ops-mirror
Beta Was this translation helpful? Give feedback.
All reactions
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.
All reactions
1 reply
-
That worked, thanks!
Beta Was this translation helpful? Give feedback.
All reactions
Answer selected by
TomasMikula
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment