Skip to content

Instantly share code, notes, and snippets.

@tstone
Last active November 11, 2022 10:29
Show Gist options
  • Save tstone/159e94bd3de7e43e3b1a to your computer and use it in GitHub Desktop.
Save tstone/159e94bd3de7e43e3b1a to your computer and use it in GitHub Desktop.
val vs. lazy val for implicit class's in Scala
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