Pattern matching lets you automatically execute code based on some piece of data. Scala uses pattern matching often, such as when you parse XML or pass messages between threads. Basic syntax of pattern
In Scala, an instance of Set can be declared as follows.
val s = (1 to 6).toSet
Principle difference between sets and sequences are three:
* Sets are unordered
val s = (1 to 6)
Fold is a general purpose operation on list (e.g., List[A]), which involves iterating (over each element) and applying a binary function--
f: A -> B -> B
to reduce the list
Functions in Scala can be defined simply as follows:
def fnname (args)={
// function body
}
Implementing loop can be done in following manner.
def whileLoop{
var i = 1
while (i<=3) {
println (i)