Scala Cheat Sheet
Scala syntax, case classes, pattern matching, immutable collections, and functional programming features that run on the JVM.
2 PagesAdvancedApr 15, 2026
Basic Syntax
Values, variables, and control flow.
scala
val age = 30 // immutable valuevar count = 0 // mutable variableval name = "Ada"val pi: Double = 3.14159if (age >= 18) { println(s"$name is an adult")}for (i <- 0 until 5) { println(s"Count: $i")}
Case Classes & Pattern Matching
Idiomatic data modeling and dispatch.
scala
case class Point(x: Int, y: Int)val p = Point(1, 2)val p2 = p.copy(y = 5) // immutable updatedef describe(x: Any): String = x match { case 0 => "zero" case n: Int if n > 0 => "positive" case Point(0, 0) => "origin" case Point(_, _) => "some point" case _ => "unknown"}
Collections
Immutable, functional collection operations.
scala
val nums = List(5, 3, 1, 4, 2)val evens = nums.filter(_ % 2 == 0) // List(4, 2)val squared = nums.map(n => n * n) // List(25, 9, 1, 16, 4)val sum = nums.sum // 15val sorted = nums.sorted // List(1, 2, 3, 4, 5)val opt: Option[Int] = nums.find(_ > 10) // None
Core Keywords
Common Scala language keywords.
- val/var- immutable and mutable bindings (prefer val)
- case class- immutable data class with structural equality and copy()
- object- defines a singleton (used for companion objects, static-like members)
- trait- reusable interface that can hold implementation, mixed in with 'with'
- Option[T]- Some(value) or None instead of null
- match- powerful pattern-matching expression
- for (a <- xs) yield- for-comprehension producing a new collection
- implicit- compiler-provided parameter or conversion (use sparingly)
Pro Tip
Prefer immutable `val` and persistent collections (List, Vector) over mutable ones — Scala's collections are optimized for structural sharing, so copies are cheap.
Was this cheat sheet helpful?
Explore Topics
#Scala#ScalaCheatSheet#Programming#Advanced#BasicSyntax#Case#Classes#Pattern#OOP#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance