Scala collections systematically distinguish between mutable (scala.collection.mutable) and immutable (scala.collection.immutable) collections. A mutable collection can be updated or extended in place. This means you can change, add, or remove elements of a collection as a side effect. Immutable collections, by contrast, never change. You have still operations that simulate additions, removals, or updates, but those […]
Category: Scala
Mastering Scala Basics: Sequencing Computations
Generic types allows us to abstract over types. If we don’t care what type is stored but we want to make sure we preserve the type when we get the value out, then use a generic type. Generic classes or traits takes a type parameter within a square bracket [ ]. The Scala convention is […]
Mastering Scala Basics: Modeling Data with Traits
Traits allow us to express that multiple classes share a common super-type. Traits are similar to Java’s interfaces and can be thought of abstraction over classes. // Trait declaration trait TraitName { declarationExpression } // declare class is a subtype of trait class Name(…) extends TraitName { … } Two ways that traits are different […]
Mastering Scala Basics: Objects & Classes
Just like other programming languages, we use class to create objects that have similar methods and fields. In addition, class in Scala defines a type and the objects created from a class share the same type. class Employee { val name = "John" val id: Int = 10 def details = name + ":" + […]
Mastering Scala Basics: Expressions, Types, Values & Methods
Expressions are parts of a program that evaluate to a value. For example: val a = 3 + 5 // a evaluates to 8 A value is an information stored in computer’s memory and exists at run time. In the above example, values 3 and 5 are combined to create another value 8. Types restrict […]
Streamlining Your Scala Development: A Guide to Creating SBT Projects in Eclipse
Hey there, I’m currently knee-deep in a Scala course on Coursera called "Functional Programming in Scala" taught by none other than Martin Ordersky – the inventor of Scala. Let me tell you, creating a Scala ecosystem is no walk in the park. Recently, I hit a roadblock while trying to create an Eclipse project using […]