When
programs get larger, you need some way to divide them into smaller, more
manageable pieces. For dividing up control flow, Scala offers an approach familiar
to all experienced programmers: divide the code into functions.
In fact,
Scala offers several ways to define functions that are not present in Java.
The most
common way to define a function is as a member of some object; such a function
is called a ‘method’.
The main function in Scala is defined as,
def
main(args: Array[String]) {
Functions in Scala are called First
Class Citizens. Not only can you define functions and call them, but you can
write down functions as unnamed literals and then pass them around as values. In other words, If you can treat a Function as a Value, it is a First Class Function.
a) We can assign an object to a function à function object.
b) We can
assign one function object to another function object.
c) Function
object can be passed as a parameter to another function / method.
d)
Functions object are returned from a method or
function.
Point’s
c & d are Higher Order Functions.