Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active February 23, 2019 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renaudcerrato/e02d269b7e66d991bdb0ec2496bd67f1 to your computer and use it in GitHub Desktop.
Save renaudcerrato/e02d269b7e66d991bdb0ec2496bd67f1 to your computer and use it in GitHub Desktop.
Kotlin Infix Functions
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