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. In this course, you’ll join Scala expert Daniel Hinojosa for a hands-on, in-depth exploration of Scala for users who want to take their Scala skills up a level. You’ll learn the intricate art of pattern matching, how to create your own extractors, and develop a deeper understanding of Scala implicits, implicit classes, and typeclasses.

The course uses a mix of lectures, Q&A sessions, and realistic code examples. Daniel includes simple quizzes throughout the course to track your progress, and provides hands-on lab exercises.

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 are an intermediate Scala developer looking for a deeper knowledge in pattern matching, implicits, and typeclasses
  • You are interested in the Scala language and want to learn some of the heftier features
  • You currently develop in another functional language, and are interested in how Scala handles pattern matching and retrofitting pre-made classes to add some implementations of your own

Prerequisites

  • Intermediate object oriented and functional programming knowledge
  • Basic Scala programming knowledge or completed an introduction to Scala video course, such as O’Reilly’s Beginning Scala Programming.

Prerequisite Setup for Class

Java 8 must be installed!  No exceptions!

The following commands must work on your command line:
    javac -version
    java -version

If these do not render a version, please fix your JAVA_HOME environment variable and your PATH.

Also be sure to install SBT, which is a Scala based build tool since we will require that for our class. 

Get the latest sbt at http://www.scala-sbt.org/download.html

Then, if applicable follow directions at this location:

http://www.scala-sbt.org/0.13/docs/Manual-Installation.html

Once done, you should be able to verify that sbt is working by invoking the following at the command line:

sbt sbtVersion

Also, be sure to have the LATEST favorite IDE or editor installed with all updates loaded before attendance. That means, Eclipse should be preferably at Neon or you can just download the scala-ide installation.  IDEA should be at a 2016.x series. If you are old school and wish to use Vim or Emacs or maybe you are new school and wish to use any of the newer editors like Sublime, Atom, VSCode, etc please have those setup before class and research any Scala code highlighting tools that can be aid in your development and install those plugins.  I will be exclusively using both Eclipse and IDEA for our class.

Finally, install respective Scala plugins for your IDEs or Editors. For Eclipse, checkout scala-ide.org for the update site, you call also visit the Eclipse Marketplace and install Scala-IDE plugin. 

For IntelliJ IDEA visit the plugins section in your IDE and install the 'Scala' plugin (Do not install the IntelliJ 'sbt' plugin as it is incompatible with the Scala plugin)

NOTE: There is no need to download Scala itself, since SBT will handle the Scala set up for you.

Recommended Preparation:

Beginning Scala Programming
Programming Scala ch.6
Programming Scala ch.8

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