Skip to content

Instantly share code, notes, and snippets.

@prasanthperumal92
Created April 30, 2024 10:46
Show Gist options
  • Save prasanthperumal92/25d94bd657130cdc85ba962cae76f070 to your computer and use it in GitHub Desktop.
Save prasanthperumal92/25d94bd657130cdc85ba962cae76f070 to your computer and use it in GitHub Desktop.
A goofy sample on why infix keyword is a game changer
open class Animal{
infix fun has(value:Int):Animal{
return this
}
infix fun legs(value:Animal):Animal{
return this
}
infix fun a(value:Any):Animal{
return this
}
}
object and: Animal()
object tail: Animal()
fun main(){
val dog = Animal()
dog has 4 legs and a tail
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment