Last active
February 23, 2019 06:22
-
-
Save renaudcerrato/e02d269b7e66d991bdb0ec2496bd67f1 to your computer and use it in GitHub Desktop.
Kotlin Infix Functions
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
class Price(val value: Double, val currency: Currency) | |
infix fun Int.euro(cents: Int): Price { | |
return Price(toDouble() + cents / 100.0, Currency.EURO) | |
} | |
val price = 1 euro 42 | |
// equivalent to: | |
val price = 1.euro(42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment