⚛ Scala — Learn From Zero

Playground: Scastie — click, type, run.

What is Scala?

Scala blends object-oriented and functional programming on the JVM. Great for data engineering (Spark) and scalable backends.

  • Big data (Apache Spark)
  • Backend services (Play, Akka)
  • Distributed systems
  • Functional pipelines

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

scala
object Main {
  def main(args: Array[String]): Unit =
    println("Hello, world!")
}

Programs live in objects.

Variables

scala
val name = "Ada"
var age = 36

Prefer val.

If / Else

scala
val age = 18
val msg = if (age >= 18) "Vote" else "Too young"

If is an expression.

Loops

scala
for (i <- 0 until 5) println(i)
(1 to 3).foreach(println)

Use until / to.

Functions

scala
def add(a: Int, b: Int): Int = a + b

Types after parameter names.

Collections

scala
val nums = List(1, 2, 3)
val even = nums.filter(_ % 2 == 0)

Immutable by default.

🟡 Intermediate — Building Real Programs

Case Classes

scala
case class Person(name: String, age: Int)
val p = Person("Ada", 36)

Automatic equality, copy, match.

Pattern Matching

scala
x match {
  case 0 => "zero"
  case n if n > 0 => "pos"
  case _ => "neg"
}

Exhaustive, powerful matching.

Traits

scala
trait Animal { def speak(): Unit }
class Dog extends Animal { def speak() = () }

Interfaces with implementations.

Higher-Order Functions

scala
val apply = (f: Int => Int, x: Int) => f(x)

Functions as values.

Option

scala
val o: Option[Int] = Some(5)
val v = o.getOrElse(0)

No nulls; use Option.

🔴 Advanced — Pro Concepts

Implicits

scala
implicit val ord: Ordering[Int] = Ordering[Int]
List(3,1,2).sorted

Type-class style resolution.

Futures

scala
import scala.concurrent.Future
Future { expensiveWork() }

Async computations.

For-Comprehensions

scala
for {
  a <- optA
  b <- optB
} yield a + b

Chain monadic operations.

Macros

scala
import scala.quoted.*
inline def twice(n: Int): Int = ${ }

Compile-time metaprogramming.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.