Last active
November 11, 2022 10:29
-
-
Save tstone/159e94bd3de7e43e3b1a to your computer and use it in GitHub Desktop.
val vs. lazy val for implicit class's in Scala
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
implicit class StringOps(s: String) { | |
val one = { println("one"); "one" } | |
val two = { println("two"); "two" } | |
lazy val three = { println("three"); "value" } | |
} | |
scala> "asdf".three | |
one | |
two | |
three | |
res1: String = value | |
scala> "asdf".two | |
one | |
two | |
res2: String = two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment