typestar

Language basics

27 steps in 9 sets of Scala.

Scala runs functional programming on the JVM at industrial scale: Spark, Kafka, and half the big-data stack are written in it, and it compiles to the same bytecode Java does while saying twice as much per line. Scala 3 is the dialect here — the braceless, indentation-based syntax with enums, extension methods, and top-level definitions that made the language feel a decade younger.

This tour covers the everyday core: vals and type inference, expressions everywhere (if and match return values), methods and lambdas, the immutable collections and their map/filter/fold toolkit, case classes with copy, enums, Option and Either instead of null and exceptions, and traits with extension methods. The encore ships complete programs. Every seed compiles under scalac -Werror with unused-checking on, and the encore runs start to finish.

Start this tour

Values & types

  • val & varA ferry seat count held in val bindings, with one var for the number that really changes.
  • Type inferenceThe compiler reads Int, Double, String and List types off the values you write.
  • String interpolationThree interpolators: s for values, f for formatted output, raw for untouched escapes.

Expressions

  • if as an expressionif/else evaluates to a value in Scala, so it can be assigned straight to a val.
  • match basicsMatching on plain values, with alternatives, guards, and a catch-all.
  • for loopsThree shapes of for: over a collection, over .indices, and with two generators.

Functions

  • Defining methodsdef with typed parameters and a return type, first as an expression and then as an indented body.
  • Default & named argumentsParameters that carry defaults, and calls that name their arguments instead of ordering them.
  • Lambdas & function valuesFunction literals, the _ shorthand, and a method that takes a function as a parameter.

Collections

  • ListsA tide log held in a List, extended at both ends and read back safely.
  • MapsA seed drawer as a Map, read two different ways and updated without mutation.
  • SetsA set of studied chess openings, tested for membership and combined against a rival repertoire.

Transformations

  • Map and filterBakery order counts run through map and filter, alone and chained.
  • FoldingCrate weights collapsed to a total, then to a string and to a Map.
  • For comprehensionsOrchard rows turned into new collections with for and yield.

Case classes & enums

  • Case classesA Lighthouse record with generated printing and equality, taken apart by a match.
  • Copy updatesKiln firings revised with copy, which builds a new value and leaves the old one alone.
  • EnumsA signal enum matched exhaustively, and a second enum whose cases carry data.

Option & Either

  • OptionScala's answer to null: a value that is either there or admits it is not.
  • Chaining OptionsTwo dependent lookups and a test, with no null check anywhere.
  • Either for validationEither keeps the reason a value was rejected, where a bare Option cannot.

Traits & extensions

  • TraitsA trait fixes what every shape must answer and writes the shared part once.
  • Extension methodsAdding methods to Int and String without owning either type.
  • Objects and companionsAn object is a namespace with one instance; a companion is where constructors go.

Encore

  • word_freq.scalaA whole report: normalize a passage, count its words, rank and print them.
  • grade_report.scalaPer-student averages, letter grades and a class summary from an inline roster.
  • temp_stats.scalaOne week of high temperatures as a table of stats and a bar chart.

The other Scala tours