Scala

Scala Traits

Scala Traits defines object types by providing signature of the supported methods. This tutorial provides a quick introduction to Scala Traits. Some key points on Scala Traits. Scala Traits are like interfaces in Java.  Scala Traits can have default implementations for certain methods unlike Java interfaces.  Scala Traits don’t have any constructor parameters. Scala class …

Scala Traits Read More »

Scala Case Classes

Scala supports an interesting construct called case classes with the intent of creating immutable objects that can be used in pattern matching. This article provides a quick introduction to Scala case classes with examples. A case class is created by adding the keyword case before the class definition. case class Employee Scala Case Classes can …

Scala Case Classes Read More »

Scala Classes

Like any object oriented programming language Scala allows to define classes which is the code template for creating objects. This article provides a quick introduction to work with Scala classes. Scala Classes, Fields and Methods Scala Class is the extensible static code template that can be initiated into objects at run time. Class definition in …

Scala Classes Read More »

Scala Currying Functions

Currying converts a function with multiple arguments into a series of a functions with single argument. This article provides an introduction to Scala Currying Functions. Scala Currying Functions is often confused with Scala Partially Applied Functions. Both currying and partial application enables creation of derived functions with smaller number of arguments. Key difference is that in …

Scala Currying Functions Read More »

Scala Partially Applied Functions

To invoke functions requires us to specify all the function parameters. Scala provides a construct called Partially Applied Functions where a function invocation can be reused by retaining some of the parameters without the need to type them again. Partial application enables conversion of a function with multiple arguments into one with fewer arguments with …

Scala Partially Applied Functions Read More »

Scala Anonymous Functions

Scala  supports a facility to avoid naming functions. This provides convenience when working with higher order functions where the need is to pass a function as a parameter to another function. These are referred to as anonymous functions or function literals.  A simple anonymous function. (x : Int) => x * x Here x : Int is the parameter …

Scala Anonymous Functions Read More »

Scala Higher Order Functions

Scala is also a functional programming language and allows the definition of higher order functions. Functions that take other functions as parameters or whose result is a function are called higher order functions (HOF). In Scala functions are treated as first class values which can be passed as parameters and returned as a result. Let …

Scala Higher Order Functions Read More »

Scala Functions

Scala is also a functional language and provides the flexibility to the programmer to use classes and methods as in a object oriented language along with pure functions. Functions in Scala are also objects. This article provides a brief introduction to using functions in Scala. def is keyword used to define functions in Scala. A …

Scala Functions Read More »

Scala Companion Object

This article provides a brief introduction to an interesting concept the Scala Companion Object. Scala doesn’t have static variables and methods. Scala Companion Object can be visualized as a place holder for all the static variable and method needs of a Scala class.  Scala Companion Object has the same name as an associated Scala class …

Scala Companion Object Read More »

Scala Objects

For programmers already familiar with C++ or Java the concept of object in Scala looks interesting. In Scala object is a keyword and implicitly creates a singleton which is guaranteed to be unique. There is a anonymous class created for every object. It is important to note that Scala doesn’t have static methods or fields …

Scala Objects Read More »