Created
April 20, 2024 13:35
-
-
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
This file contains 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.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