Hi,
To create a Scala function, we use the keyword ‘def’. Here is the syntax you can follow:
def functionName(parameters:typeofparameters):returntypeoffunction={
//statements to be execute
}
Here you must mention the types of parameters, the type of Scala function is optional.
Now for Example:
scala> def sayhello(){
| println("Hello")
| }
sayhello: ()Unit
Now lets call it:
scala> sayhello()
Since we make this function return nothing, it returns Unit. All that this Scala function does is take no parameters and simply print Hello.