Category: Scala

0-arity Functions: () => Type

1
2
3
4
5
6
7
8
() => println("I'm an anonymous function")  // anonymous function
 
val f: () => Unit = () => println("I'm an anonymous function")
f() // return I'm an anonymous function
 
// () => println("I'm an anonymous function") is an anonymous function
// f has type - () => Unit,
// a function takes no argument and return Unitn
Tags :

Call-by-Name: => Type

1
2
3
4
def f(x: => Int) = x * x * x
var y = 0
f { y += 1; y }
// result = 6
Tags :