import
The scala equivalent of java's import keyword is the same "import". However, the wildcard * used in java is replaced by _ in scala. Here's how an import statement looks like:
import scala.io._
def
This defines a function and looks like so:
def sum(in: Seq[String]) = {
// The body of the function goes here
def sum(in: Seq[String]) = {
// The body of the function goes here
}
This defines a function that takes one argument, a sequence of string. In scala, it is not mandatory to indicate the return type. The compiler does it for you. However, it is a good practice to provide it. The body of a function goes in after the '='. It may be enclosed in parentheses '{' '}'. There is no return in the body of the function, and as per the rules, the last evaluated expression is the returned entity. Note: In scala function declaration, the name of the argument comes first, followed by a ":" and then comes the type of the argument. As per the functional programming paradigm, functions have no side-effects, meaning, it returns the same value no matter what, and more importantly, it does not mutate or change the values/state of any other entity/variables.
Seq[String]
Identifies an entity which is a sequence (collection) of String.
Seq[String]
Identifies an entity which is a sequence (collection) of String.