Last active
February 3, 2026 20:25
-
-
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/c1c61b858e0e5bf38d58a6f8df1e17d78fe87c57
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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