
This is part three of a three part course, the first part covers converting to Scala from other programming languages and part two covers Scala language features that might be different from other languages or perhaps even unique. This part three finishes the tour of powerful language features with case classes and pattern matching, then moves on to the most important core library features, like collections, futures, and also covers building and working with Java.
Slides and exercises are attached to the next lecture.
Explore advanced Scala pattern matching, including guards, type narrowing, try, case classes and constructor patterns, and core libraries like options, collections, and tuples, plus custom extractors.
Explore Scala's match construct with constant matches, learn how it differs from Java switch, and see how case underscore handles all other cases with a unit side effect.
Use pattern match as an expression to map a string to a result, returning different strings for inputs like fish and chips, bacon and eggs, or tea and scones.
Explain how Scala pattern matching distinguishes constants from variables using capitalization, with max limit as a constant and min limit as a variable, via def is a limit.
Explore option types as a safe alternative to nulls and practice pattern matching on options with guards, case clauses, and none handling, including idiomatic getOrElse usage.
Case classes automatically generate equals and hashCode, with pattern matching limitations preventing inheritance of other case classes. They expose constructor parameters as public parametric fields, enabling direct access like address.city.
Learn typed pattern matches in scala to narrow types safely, replacing runtime checks and casts with type patterns like case i of int, enabling guards and method calls.
Discover how vals enable pattern matching in Scala, using tuples and case class extractors to pull out fields like name, phone, and post code, and understand match errors.
Explore how partial functions become pattern matches in Scala, using curly brace cases to define either partial or complete functions, and replace map calls with direct pattern matching.
Enforce exhaustiveness with sealed class hierarchies in Scala to ensure pattern matching covers all algebraic data types, and receive compile-time warnings on missing cases to avoid runtime errors.
Explore how Scala case classes generate an unapply method in the companion object to support pattern matching, returning an option of the first name, last name, and age.
Learn to implement custom extractors in scala using an unapply method, returning options, to parse coordinate strings into latitude and longitude with pattern matching.
Learn to implement custom seq extractors in Scala by using unapply seek to extract any number of doubles from a comma-separated string, enabling sequence pattern matching.
Explore how immutable Scala lists build with cons and nil as a recursive data structure, share memory during concatenation, and provide efficient head operations thanks to the tail pointer.
Explore immutable lists and covariant typing in scala, mastering efficient head operations, the nil bottom type, and the cons pattern within a sealed trait list design.
Learn how to initialize lists in Scala using the apply method and right‑associative cons, with nil, and use fill, tabulate, and range to generate sequences like 0 to 9.
Convert vectors, sets, maps, and strings to lists in Scala using toList, noting set order is not guaranteed and strings become lists of chars.
Explore how fold left and fold right reduce lists with an identity value and a combiner, enabling sums, products, and string concatenation.
Explore fold alternatives in Scala applied, part 3, using built-in list operations like sum and product. Demonstrate make string with a separator, preamble, and postamble to intersperse words.
Sort lists in Scala using sort with, sort by, and sorted with implicit orderings for strings and integers, and supply a custom implicit person ordering to ensure stable, prioritized sorting.
Explore powerful collection methods in Scala, including transpose, flatten, and sum, and learn to group by to build a histogram from data.
Convert collections to list, vector, array, set, or map with concise to-type methods, noting maps require a sequence of pairs. Expect 2.13 syntax shifts to to queue and builder usage.
The mighty vector in scala uses a 32-ary immutable trie to deliver near constant performance with memory reuse, where updates create new blocks along the path and require few hops.
Demonstrates how a vector with arity 32 enables navigation in at most seven hops, updates by duplicating 32-word blocks, and shows vector outperforms list on the JVM.
Explore immutable sets, their unique elements, and non-ordered storage. Use set operations: intersect, diff, and union, plus the apply method as a predicate to count vowels.
Explore immutable collections in Scala, including list, stream, vector, stack, and queue ranges. Cover hash sets and maps, small-arity optimizations, tree variants, bit-set encoding, and avoid list.map.
A view is a lazy, functional collection based on an existing one without modifying it, recording mapped functions and applying them just in time, trading off sparse access against iteration.
Continue module 14 exercises, using provided implementations to compare your versions, and practice constructing a mutation or polymorphism map before advancing to sbt and Java libraries in module 15.
Explore building Scala projects with Scala and Java together, navigate edge cases, master SBT as the primary build tool, and discuss other options while constructing custom tasks.
Explore Gradle as a popular build tool with polyglot support. Learn how Gradle's Groovy domain-specific language, a Scala plugin, and zinc incremental compiler make including Scala in your builds easy.
Explains the conventional sbt project layout, with sources under source/main/scala, resources, and tests under test, mirrored for integration tests, plus Play's slight deviations and an IntelliJ example.
Master the build.sbt file basics, including a minimal build file, a Scala-like DSL with three key operators (:=, +=, ++=), optional blank lines, and embedding Scala code inside curly braces.
Explore a minimal sbt build, with project name, organization, licenses, and compiler options. Understand scala versions, cross compilation, percent vs percent percent dependencies, and plugin publishing to bintray.
Discover how sbt plugins extend build capabilities via a plugins.sbt file under the project directory, and configure resolvers and plugins such as the bin tree and git plugins.
learn how to create a custom sbt setting and task, define setting keys and boolean flags, and compose them to mark a project as awesome.
Define a custom task key check awesome that depends on the test compile task, forces compilation, and logs the project's awesome rating.
Learn how to call Java from Scala, import Java libraries, and use Java methods with Scala syntax, including infix calls, primitive boxing, and SAM conversions on the JVM.
Scala 2.12 with Java 8 enables lighter function literals that compile to method handles. Scala functions now act as Java function interfaces with single abstract methods and Java 8 streams.
Wrap Java results that may be null in an option to convert them to Some or None, then safely map over the option to avoid null pointer exceptions.
Learn how to convert java.util collections to Scala collections using Java converters, map over Java lists, and obtain an immutable list with toList, while mindful of mutability.
Explore Scala and Java interoperability with empty trait based APIs, avoid risky function literals, convert between nulls and options, and use Scala Java converters and REPL to explore libraries.
Practice module 15 by calling a fake Java library in tests to explore booleans, nulls, and array lists of integers, gaining Scala–Java interop fluency; module 16 covers futures.
Explore asynchronous programming in Scala using futures built into the core libraries. Learn how these futures enable concurrent programming and leverage Scala's concurrent library support.
Learn how futures work: they start and may be unresolved, completed with success, or completed with failure; using map or flatMap keeps the thread unblocked while returning a future result.
Learn how to compose futures in Scala for non-blocking asynchronous programming, using map, flatMap, and for expressions to chain results without blocking.
Explore non blocking future operations like map, flatMap, collect, and filter, and narrow a future of any to a specific type with success or failure. Use transform to handle outcomes.
Explore how futures handle unresolved, successful, and failed states, and learn three recovery patterns, fallback to, recover, and recover with, to transform failures into usable results.
Handle an unknown number of futures with Future.sequence, turning a list of futures into a single future of a list; use traverse to map and sequence in one step.
Explore future sequence operations like first completed, futures reverse, and foldleft over a future of sequence, noting non-cancelable futures, non-blocking processing, and the empty-sequence risk of reduce left.
Explore the Scala futures mechanism by creating a promise as the server-side channel for a result, then push a value or exception to complete the future non-blockingly.
Explore how a broken promise turns a promise of int into a failed future with an exception, illustrating how failures complete promises and futures in Scala.
Explore retrying patterns for unreliable external services, using a simulated counter to model failures and eventual success, and implement a framework to retry until success.
Scala Applied, part 3 is the final part of this Scala programming language course. The course in its entirety is aimed at giving you a full, day-to-day working knowledge of Scala programming, including some of the most common core library APIs.
This part starts with a final language feature for Scala (continuing from the other language features covered in parts 1 and 2). Pattern matching, partial functions and case classes are examined, how they can be used together, and how partial functions can help you avoid certain runtime errors by validating input to a function before you call it.
Then we delve into the collections API in the core libraries (a very in-depth 2 module examination of the capabilities and performance tradeoffs of the various collection options), and finish up with a look at using Scala on Java projects, using Java libraries from Scala and how to harness build tools (particularly SBT) to build your project and even write custom settings and tasks. Following that we look at the Futures API in the core libraries.
This course is also a good lead-in to the Stairway to Scala Advanced 3 part course which concentrates on in-depth language features, higher level functional abstractions, common patterns and idioms, type theory and other more advanced Scala concepts that will be particularly helpful for anyone writing their own libraries and APIs in Scala.