Last active
April 4, 2018 12:23
-
-
Save frgomes/987fbcfed78e3742582236ec323e6000 to your computer and use it in GitHub Desktop.
Scala - implicit extension methods (pimp my library) using implict value classes
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
//------------------------------------------------------------------------ | |
// 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