Created
May 17, 2017 15:49
-
-
Save valdo404/1ac0834359ca300570de8ec4fb282ce5 to your computer and use it in GitHub Desktop.
euros
This file contains hidden or 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
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