Skip to content

Instantly share code, notes, and snippets.

@paul-lysak
Created March 14, 2016 14:25
Show Gist options
  • Save paul-lysak/d41dbd8c388b4e5fd97d to your computer and use it in GitHub Desktop.
Save paul-lysak/d41dbd8c388b4e5fd97d to your computer and use it in GitHub Desktop.
Example of separation between data and behavior with implicit conversions
SomeData.scala:
case class SomeData(a: Int, b: Int)
AdditionExtensions.scala:
object AdditionExtensions {
implicit class SomeDataConversion(d: SomeData) {
def add = d.a + d.b
def add1 = d.a + d.b +1
...
}
}
some other class:
import AdditionExtensions._
val myData = SomeData(2, 3)
println(myData.add) //5
println(myData.add1) //6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment