Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

transparent inline apply: how to achieve the apply syntax sugar? #19994

Discussion options

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)?

You must be logged in to vote

A workaround for this is

- transparent inline def apply =
+ transparent inline def apply(using inline di: DummyImplicit) =

Replies: 2 comments 1 reply

Comment options

I am also looking for something like this for ops-mirror

You must be logged in to vote
0 replies
Comment options

A workaround for this is

- transparent inline def apply =
+ transparent inline def apply(using inline di: DummyImplicit) =
You must be logged in to vote
1 reply
Comment options

That worked, thanks!

Answer selected by TomasMikula
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /