Course

Scala from the ground up

One language for scripts and services

  • Beginner
  • 12 chapters
  • 192 min read

Learn Scala by running it: the object that makes a program, values and types, text with s"...", if and match as expressions, for and while, functions and function values, classes and case classes, lists and their methods, maps and sets, traits, Option, and a capstone that groups records into a sorted, padded report.

What You'll Learn

  • Write and run a program that starts as an object extending App and prints a line
  • Hold values in val and var, and know what whole-number division really does
  • Build text with s"..." interpolation and use length, trim, split and contains
  • Branch with if as an expression, and match on numbers, strings and guards
  • Repeat work with to, until, by and while, and loop over a list
  • Write defs with parameters, return types, defaults and named arguments
  • Build classes with constructors, and case classes with copy and pattern matching
  • Transform lists with map, filter, foldLeft, sum, sortBy and mkString
  • Look values up in a Map and a Set, with get, getOrElse and updated
  • Share behaviour with a trait, and print a list of the trait type polymorphically
  • Answer questions that may be empty with Option, getOrElse, map and flatMap
  • Assemble a grouped, sorted and padded report from case classes

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick

Course Content

  1. 01
    Your first Scala program

    What Scala is, the object with a main body every program starts from, and how to print a line of text on the screen.

    Beginner · 13 min read

    Not started
  2. 02
    Values, variables and types

    val for a name you set once and var for one you change, the four types you will use daily, and what division really does to whole numbers.

    Beginner · 14 min read

    Not started
  3. 03
    Text and string interpolation

    Text as a value you can ask questions of, the s before the quotes that puts a name inside a sentence, and the methods that measure, trim and split a line.

    Beginner · 14 min read

    Not started
  4. 04
    Decisions: if and match

    if as an expression that hands back a value, match as a decision table over numbers and strings, guards, and the underscore that catches everything left.

    Beginner · 14 min read

    Not started
  5. 05
    Loops: for and while

    Ranges with to, until and by, a while loop with a counter that has to move, a for over a list, and building a line of text one pass at a time.

    Intermediate · 15 min read

    Not started
  6. 06
    Functions and function values

    def with parameters and a return type, defaults and named arguments, a function held in a val, and a lambda handed straight to map.

    Intermediate · 16 min read

    Not started
  7. 07
    Classes and case classes

    A class with a constructor and its own toString, then the same record as a case class, where copy, value equality and pattern matching come for free.

    Intermediate · 17 min read

    Not started
  8. 08
    Lists and their methods

    An ordered collection that never changes, and the methods that do the looping for you: map, filter, foldLeft, sum, sortBy, mkString, zip, take and drop.

    Intermediate · 16 min read

    Not started
  9. 09
    Maps and sets

    A Map for lookups by key and a Set for values that appear once, with get, getOrElse and updated, and a sorted print so the output is the same every run.

    Advanced · 17 min read

    Not started
  10. 10
    Traits and shared behaviour

    A trait that states what a type can do, one method written once inside it, two classes that fill in the blanks, and a list of the trait type printed by one loop.

    Advanced · 18 min read

    Not started
  11. 11
    Option, or a value that may be missing

    Some and None, getOrElse for a fallback, map and flatMap for chains of lookups, a match to open one by hand, and a function that says in its type that it may find nothing.

    Advanced · 18 min read

    Not started
  12. 12
    Putting it together: a sales report

    A case class for the rows, groupBy and a sum per group, sortBy for a fixed order, and f"..." with padding so the numbers line up in columns.

    Advanced · 20 min read

    Not started