Skip to content

Instantly share code, notes, and snippets.

@droid-lover
Created February 27, 2023 11:48
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 droid-lover/a38ea65f6fb9f73dfb88dca22eb565a4 to your computer and use it in GitHub Desktop.
Save droid-lover/a38ea65f6fb9f73dfb88dca22eb565a4 to your computer and use it in GitHub Desktop.
/**
* Native Mobile Bits Evening Coding Paper @5pm IST
* "Infix - very useful"
*/
fun main() {
// val result = 20.add(3) Traditional way
val result = 20 add 3 //with Infix function
println(result)
val fruits = setOf<String>("apples","oranges")
//println("oranges".isInMenu(fruits)) Traditional way
//println("mangoes".isInMenu(fruits)) Traditional way
println("oranges" isInMenu fruits) //with Infix function
println("mangoes" isInMenu fruits) //with Infix function
}
infix fun String.isInMenu(setOfFruits:Set<String>) :Boolean{
return setOfFruits.contains(this)
}
infix fun Int.add(number: Int): Int {
return this + number
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment