Skip to content

Instantly share code, notes, and snippets.

@valdo404
Created May 17, 2017 15:49
Show Gist options
  • Save valdo404/1ac0834359ca300570de8ec4fb282ce5 to your computer and use it in GitHub Desktop.
Save valdo404/1ac0834359ca300570de8ec4fb282ce5 to your computer and use it in GitHub Desktop.
euros
object Euros {
trait Currency
case class Euro(int: Int) extends AnyVal with Currency {
def +(m: Euro): Euro = new Euro(int + m.int)
}
implicit class EuroToInt(int: Int) {
def `€` = {
Euro(int)
}
}
}
object CurrencyApp extends App {
import Euros._
val cagnotte: Euro = 0 `€`
println(cagnotte + (1 `€`))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment