Skip to content

Instantly share code, notes, and snippets.

@amrza
Created November 2, 2018 16:14
Show Gist options
  • Save amrza/2f3edb30677b87593bb9a9227df43a34 to your computer and use it in GitHub Desktop.
Save amrza/2f3edb30677b87593bb9a9227df43a34 to your computer and use it in GitHub Desktop.
fun with infix funs in kotlin
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