Created
November 2, 2018 16:14
-
-
Save amrza/2f3edb30677b87593bb9a9227df43a34 to your computer and use it in GitHub Desktop.
fun with infix funs in kotlin
This file contains 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
import Foods.* | |
import Sports.* | |
import Superpowers.* | |
enum class Foods { pizza, fesenjoon } | |
enum class Sports { football, volleyball } | |
enum class Superpowers { fly, disappear } | |
data class Person(val name: String) | |
infix fun Person.like(food: Foods) = println("${name} likes ${food}.") | |
infix fun Person.play(sport: Sports) = println("${name} plays ${sport}.") | |
infix fun Person.can(superpower: Superpowers) = println("What?...he can ${superpower}?😳") | |
fun main() { | |
val i = Person("Amirreza") | |
i like pizza | |
i play football | |
i can fly | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment