Scala Introduction

Scala Introduction Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. Scala is object-oriented Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described […]

Read More →
Scala – Overview

Scala, short for Scalable Language, is a hybrid functional programming language. It was created by Martin Odersky. Scala smoothly integrates the features of object-oriented and functional languages. Scala is compiled to run on the Java Virtual Machine. Many existing companies, who depend on Java for business critical applications, are turning to Scala to boost their […]

Read More →
Scala – Environment Setup

Scala can be installed on any UNIX flavored or Windows based system. Before you start installing Scala on your machine, you must have Java 1.8 or greater installed on your computer. Follow the steps given below to install Scala. Step 1: Verify Your Java Installation First of all, you need to have Java Software Development […]

Read More →
Basics

Basics of Scala   In this page, we will cover basics of Scala. Trying Scala in the Browser You can run Scala in your browser with ScalaFiddle. Go to https://scalafiddle.io. Paste println(“Hello, world!”) in the left pane. Hit “Run” button. Output appears in the right pane. This is an easy, zero-setup way to experiment with pieces of Scala […]

Read More →
Unified Types Scala

Unified Types   In Scala, all values have a type, including numerical values and functions. The diagram below illustrates a subset of the type hierarchy. Scala Type Hierarchy Any is the supertype of all types, also called the top type. It defines certain universal methods such as equals, hashCode, and toString. Any has two direct subclasses: AnyVal and AnyRef. AnyVal represents value types. There are […]

Read More →
Classes in Scala

Classes   Classes in Scala are blueprints for creating objects. They can contain methods, values, variables, types, objects, traits, and classes which are collectively called members. Types, objects, and traits will be covered later in the tour. Defining a class A minimal class definition is simply the keyword class and an identifier. Class names should be capitalized. class […]

Read More →
CLASS COMPOSITION WITH MIXINS

Mixins are traits which are used to compose a class. abstract class A { val message: String } class B extends A { val message = “I’m an instance of class B” } trait C extends A { def loudMessage = message.toUpperCase() } class D extends B with C val d = new D println(d.message) […]

Read More →
HIGHER-ORDER FUNCTIONS

Higher order functions take other functions as parameters or return a function as a result. This is possible because functions are first-class values in Scala. The terminology can get a bit confusing at this point, and we use the phrase “higher order function” for both methods and functions that take functions as parameters or that […]

Read More →
NESTED METHODS

In Scala it is possible to nest method definitions. The following object provides a factorial method for computing the factorial of a given number: def factorial(x: Int): Int = { def fact(x: Int, accumulator: Int): Int = { if (x <= 1) accumulator else fact(x – 1, x * accumulator) } fact(x, 1) } println(“Factorial of 2: […]

Read More →
MULTIPLE PARAMETER LISTS (CURRYING)

Methods may define multiple parameter lists. When a method is called with a fewer number of parameter lists, then this will yield a function taking the missing parameter lists as its arguments. This is formally known as currying. Here is an example, defined in Traversable trait from Scala collections: def foldLeft[B](z: B)(op: (B, A) => B): B foldLeft applies […]

Read More →