Scala - By Name Parameters

less than 1 minute read

Syntax: => A

1
2
3
4
5
def ifElse[A](test: Boolean, whenTrue: => A, whenFalse: => A): A = test match {
   case true => whenTrue
   case false => whenFalse
}
ifElse(1 == 1, println("true"), println("false"))

By Name parameter will be evaluated when called