Last active
May 25, 2024 10:19
-
-
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/8b6d884de652ace920daab6fba40f74acddd149e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.2" | |
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