Pattern Matching

chapter, Online, 2016

Pattern Matching


Scala has a built-in general pattern matching mechanism It allows to match on any sort of data with a first-match policy — alt

  • Here is a second example which matches a value against patterns of different types: alt

    Enumeration

  • Enumeration allows programmer to define their own data type
  • Often we have a variable that can take one of several values. For instance, a WeekDays field of an object could be either Mon, Tue, Wed, or Thu alt

    Enumeration (cont’d)

  • Another way alt
  • Gives Error if value is not found alt

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...