Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active April 4, 2018 12:23
Show Gist options
  • Save frgomes/987fbcfed78e3742582236ec323e6000 to your computer and use it in GitHub Desktop.
Save frgomes/987fbcfed78e3742582236ec323e6000 to your computer and use it in GitHub Desktop.
Scala - implicit extension methods (pimp my library) using implict value classes
//------------------------------------------------------------------------
// Implicit Extension Methods a.k.a. Pimp My Library
//
// In a nutshell, this is about avoiding create instances of implicit
// classes which will live very shortly and later will be garbage
// collected, hurting hard performance in certain circumstances.
//
// More info:
// http://docs.scala-lang.org/sips/completed/value-classes.html
// http://docs.scala-lang.org/sips/completed/implicit-classes.html
//------------------------------------------------------------------------
package my.app
package object implicitsForTests {
implicit class RichValue(val v: Int) extends AnyVal {
def asFancyString: String = "{v}!!!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment