O'Reilly logo
live online training icon Live Online training

Scala: Beyond the Basics

Pattern matching, extractors, and implicits

Daniel Hinojosa

No matter how much Scala you already know, there’s always more that you can make it do. Join Scala expert Daniel Hinojosa for a hands-on, in-depth exploration aimed at users who want to take their Scala skills up a level. Through a mix of lectures, Q&A sessions, realistic code examples, and hands-on exercises, you’ll learn the intricate art of pattern matching, discover how to create your own extractors, and develop a deeper understanding of Scala implicits, implicit classes, and type classes. By the time you're through, you'll be able to write more powerful Scala code that’s concise, readable, and highly maintainable.

This class is a great follow-up if you’ve taken Daniel’s Learn the basics of Scala in 3 hours and Setting up Scala projects courses or if you already understand concepts such as manipulating variables, classes, and functions.

What you'll learn-and how you can apply it

By the end of this live, hands-on, online course, you’ll understand:

  • The basics of pattern matching in Scala
  • How to create your own extractor for pattern matching
  • How to work with and implement implicits and typeclasses

And you’ll be able to:

  • Write more powerful Scala code
  • Write Scala code that’s concise, readable, and highly maintainable
  • Advise your teammates on powerful Scala advanced features and crucial best practices

This training course is for you because...

  • You're an intermediate Scala developer looking for a deeper knowledge in pattern matching, implicits, and type classes.
  • You're interested in the Scala language and want to learn some of its more advanced features.
  • You currently develop in another functional language and want to learn how Scala handles pattern matching and retrofitting premade classes so you can add some implementations of your own.

Prerequisites

  • Intermediate object-oriented and functional programming knowledge
  • Basic Scala programming knowledge (equivalent to an introductory Scala course, such as O’Reilly’s Beginning Scala Programming)

Materials or downloads needed in advance:

  • A machine with the latest JDK 8, JDK 9, or JDK 10, Scala, the latest IntelliJ or Eclipse with the Scala and Scala-IDE plug-ins, and sbt installed and set up

Recommended preparation:

Recommended follow-up:

About your instructor

  • Daniel Hinojosa is a programmer, consultant, instructor, speaker, and recent author. With over 20 years of experience, he does work for private, educational, and government institutions. He is also currently a speaker on the No Fluff Just Stuff tour. Daniel loves JVM languages like Java, Groovy, and Scala, but he also dabbles with non-JVM languages like Haskell, Ruby, Python, LISP, C, and C++.

    He is an avid Pomodoro Technique Practitioner and makes every attempt to learn a new programming language every year. Daniel is the author of Testing in Scala and the video Beginning Scala Programming for O’Reilly. For downtime, he enjoys reading, swimming, Legos, football, and barbecuing.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Day One: Pattern Matching

Introduction (60 minutes)

  • Introduction
  • Refresher on Scala and Setup
  • Refresher on Objects and Companion Objects

Basics of Pattern Matching (60 minutes)

  • Basics Pattern Matching of Values and Defaults
  • Using Pattern Matching in Methods
  • Pattern Matching Lists – Pattern Matching Lists and as a whole
  • Pattern Matching Tuples
  • Pattern Matching Options
  • Pattern Matching Regular Expressions
  • Handling Variable Shadowing
  • Using Method Variables as Stable Variables
  • Pattern Matching Case Classes
  • Other Advanced Rules and Miscellanea

Creating your own Pattern Match (60 minutes)

  • Creating your own extractors
  • Creating your own extractors as a companion object
  • Creating list extractors
  • Revisiting Tuples, Options, etc.

Day Two: Implicits and Typeclasses

Introduction (60 minutes)

  • Introduction to Implicits
  • Implicit Parameters
  • Implicit Objects

Wrappers, Converters, and Implicitly (60 minutes)

  • Implicit Wrappers
  • Implicit Classes
  • Implicit Converters
  • Locating Implicits

– Import Strategies

– Companion Objects

– Package Implicits

  • Implicitly
  • Understanding Predef Implicits

TypeTags and Typeclasses (60 minutes)

  • View Bounds
  • Context Bounds
  • Type Tags
  • Typeclasses