Simple Scala 3 macro which generates name of the function as an opaque type.
import io.github.matejcerny.functionname.*
def someFunction(): Unit =
val fnName = functionName
println(fnName.value) // someFunctionOne use case could be logging:
def log(message: String)(using fnName: FunctionName): Unit =
println(s"${fnName.value}: $message")
def someFunction(): Unit =
log("Hello!")(using functionName)Add the library as a dependency:
libraryDependencies += "io.github.matejcerny" %% "function-name" % "0.2.2"