Traditional approach There is an approach to the Scala’s pattern matching that looks similar to the switch-case structure in C and Java: each case entry use an integer or any scalar type. Here is an example:   So if  you enter toYesOrNo(1), Scala says “yes”. And if you enter toYesOrNo(2), Scala …

Statically Typed Languages The type of every variable is known at compile time. Code is more verbose Bugs get caught quickly and easily. E.g : Java, C, C++ Dynamically Typed Languages The type of every variable is known at run time. Code is quick and dirty to write. Lots of …

Sometimes you may not know the value of your variable immediately. You can only assign your variable’s value at some later point in time during the execution of your application. Let’s assume that you need to declare a variable called msg of type String, but you won’t initialize it just yet. We’ve …

Let’s review the syntax for declaring immutable variables in Scala. As an example, you can define an immutable variable named donutsToBuy of type Int and assign its value to 5. However, through type inference, Scala complier is smart enough to figure out that the literal 5 is actually an Integer. …