Pattern Matching

  • Vishal Layka
  • David Pollak
Chapter

Abstract

So far, we’ve explored some of the basic functional cornerstones of Scala: immutable data types and the passing of functions as parameters. The third cornerstone of functional programming is pattern matching. Pattern matching provides a powerful tool for declaring business logic in a concise and maintainable way. Scala blends traditional functional programming pattern matching with object-oriented concepts to provide a very powerful mechanism for writing programs. In this chapter, we’re going to explore the basics of pattern matching. Then we’re going to see how Scala’s case classes bridge between object-oriented data encapsulation and function decomposition. Next, we’ll see how Scala’s pattern-matching constructs become functions that can be passed around and composed. Let's look at the simple example first.

Keywords

Case Class Pattern Match Class Hierarchy Visitor Pattern Object Hierarchy 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Copyright information

© Vishal Layka 2015

Authors and Affiliations

  • Vishal Layka
    • 1
  • David Pollak
    • 1
  1. 1.EvereBelgium

Personalised recommendations