September 2018
Intermediate to advanced
398 pages
9h 43m
English
A Scala function takes 0 to n parameters and returns a value. The type of each parameter must be declared. The type of the returned value is optional, as it is inferred by the Scala compiler when not specified. However, it is a good practice to always specify the return type, as it makes the code more readable:
scala> def presentation(name: String, age: Int): String = "Hello, my name is " + name + ". I am " + age + " years old."presentation: (name: String, age: Int)Stringscala> presentation(name = "Bob", age = 25)res1: String = Hello, my name is Bob. I am 25 years old.scala> presentation(age = 25, name = "Bob")res2: String = Hello, my name is Bob. I am 25 years old.
We can call a function by passing arguments ...
Read now
Unlock full access