Skip to content

Instantly share code, notes, and snippets.

@taitruong
Last active August 29, 2015 13:57
Show Gist options
  • Save taitruong/9465189 to your computer and use it in GitHub Desktop.
Save taitruong/9465189 to your computer and use it in GitHub Desktop.
infix, prefix, and postfix operators
object ScalaHackSession {
//method calls instead of infix operators
(1).+(1) //> res0: Int(2) = 2
1. + (1) //> res1: Double(2.0) = 2.0
"Hello, Scala".indexOf("a") //> res2: Int = 9
"Hello, Scala".indexOf("a", 10) //> res3: Int = 11
//method calls instead of unary prefix operators
true.unary_! //> res4: Boolean = false
(1 - 2).unary_+ //> res5: Int = -1
(1 - 2).unary_- //> res6: Int = 1
//method call instead of unary postfix operator
"Hello, Scala".toLowerCase //> res7: String = hello, scala
"Hello, Scala".toUpperCase //> res8: String = HELLO, SCALA
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment