Matching on a context function

The main issue seems to be that there’s not really a good generally applicable way to just use f in an expression when f has type A ?=> B without meaning to implicitly invoke f.

But this workaround worked for me:

transparent inline def eval[A, B](f: A ?=> B, x: A): Any =
   val f0 = a => f(using a)
   inline f0 match
      case g: (A => Future[?]) => g(x).value.get.get
      case _                   => f0(x)

eval(Future.successful(summon[Int]), 10)
eval(summon[Int] + 1, 10)
1 Like