Tag Archives: scala

Playing with reduceLeft, reduceRight, foldLeft, foldRight API in Scala

July 18, 2012

3 Comments

In our previous post we saw in detail about the foreach. map, flatMap and collect methods in the Iterable trait. In this post we will look into detail about reduceLeft, reduceRight, foldLeft, foldRight methods of the Iterable trait. These methods are almost similar in the way the operate on the collection so it should be [...]

email

Playing with Collections API in Scala

July 16, 2012

2 Comments

While I was going through the Scala collections API, I found the mere reading through the method and its functionality is not going to help. And I also realised that it will be useful if I can document them. And with that idea, I will try to document the APIs which I have tried. Please [...]

Functions as First Class Citizens in Scala

July 11, 2012

1 Comment

In Java (Java 7 and before) we can store an object reference in a variable or some primitive value in which case Classes and Primitive types are the first class citizens there, but in Scala we can assign method/function definitions to variables, we can pass around function definitions to other functions and we can even [...]

Using Apply and Unapply Methods in Scala

July 7, 2012

0 Comments

Before we proceed to learn about Apply and Unapply methods, its good to know what a companion object is. A companion object in Scala for some class say Fraction is defined as: One can provide apply(args) and unapply(args) methods in the companion objects which can be used implemented to some special operations in Scala. Suppose [...]

Traits in Scala- Advanced concepts

July 6, 2012

0 Comments

In our previous article we covered very basic concepts on traits. In this article we will expand on our initial work and explore the inherent power of traits. As we said here just like the Interfaces traits can have abstract methods. Also traits can extend other traits just like Interfaces can extend other interfaces. We [...]

Inheritance and Overriding in Scala

July 4, 2012

0 Comments

Inheritance in Scala is quite similar to the way it is in Java. The overriding aspects are a bit more detailed because in Scala there are not just methods to override but also vals, vars. There are a few restrictions added in Scala like: Overriding classes must use the “override” modifier. In Java one can [...]

Primary and Auxiliary Constructors in Scala

June 29, 2012

2 Comments

Constructors in Scala are a bit different than in Java. Scala has 2 types of constructors: Primary Constructor Auxiliary Constructor Primary Constructor In Java we have a no-args default constructor which is provided for every class which doesn’t provide its own constructor methods. On a similar lines Primary Constructor in Scala is the kind-of default [...]

Package Objects in Scala

June 28, 2012

0 Comments

Package Objects in Scala was introduced as part of Scala 2.8. With this feature a package in scala can contain field declarations, methods along with the classes, objects and traits. The methods and variable declarations are put into the package object and are accessible in the package for which the package object was declared. Lets [...]

Understanding Classes and its Fields in Scala

June 25, 2012

2 Comments

For those moving from Java to Scala would find it a bit different to see how the classes and their fields are treated in Scala. Most of you in the Java world always complain about the verbosity of adding fields and then to add their getters and setters. Lets look at how the Classes and [...]

Java HelloWorld vs Scala HelloWorld

June 17, 2012

2 Comments

As a first step into learning Scala and as one who is familiar with Java, let us compare the customary Helloworld programs in Java and Scala. You might already know that to run a Java program, there must be a public class with a main method that takes one parameter, a String[], and has a void return [...]