Skip to content

Instantly share code, notes, and snippets.

@dacr
Created April 20, 2024 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/bb0f5b6955b3e166362a4c64ae531188 to your computer and use it in GitHub Desktop.
Save dacr/bb0f5b6955b3e166362a4c64ae531188 to your computer and use it in GitHub Desktop.
scala3 feature examples - macros - inline def / published by https://github.com/dacr/code-examples-manager #4dc9d4a2-bd4a-4f02-abea-29412c842854/2cc2bced629cfe532298023410773f2088d0d1eb
// summary : scala3 feature examples - macros - inline def
// keywords : scala3, tutorial, macros, inline, meta-programming, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 4dc9d4a2-bd4a-4f02-abea-29412c842854
// created-on : 2024-03-17T08:18:10+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// Inspired from https://docs.scala-lang.org/scala3/guides/macros/inline.html
//> using scala "3.4.0"
inline def logged[T](level: String, message: => String)(inline op: T): T = {
println(s"[$level]Computing $message")
val start = System.currentTimeMillis()
val res = op
val duration = System.currentTimeMillis() - start
println(s"[$level]Result of $message: $res in ${duration}ms")
res
}
@main def go() = {
logged("INFO", "how much time"){
1+2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment