Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pattern matching in scala

Jesse cogollo
September 10, 2015

Pattern matching in scala

This presentation is a summary of pattern matching for a functional programing group ,at EAFIT university.

Jesse cogollo

September 10, 2015
Tweet

More Decks by Jesse cogollo

Other Decks in Technology

Transcript

  1. Pattern Matching DEMO Pattern Matching Jesse Javier Cogollo Alvarez Developer

    by passion email: [email protected] Functional programming group September 9, 2015 1 / 17
  2. Pattern Matching DEMO what is Pattern Matching? Is the act

    of checking a given sequence of tokens for the presence of the constituens of some pattern. https://en.wikipedia.org/wiki/Pattern_matching 3 / 17
  3. Pattern Matching DEMO characteristics • Useful Provide a powerful tool

    for declaring business logic in a concise and maintainable way. 4 / 17
  4. Pattern Matching DEMO characteristics • Basic pattern matching Allow you

    to make a programmatic choice between multiple conditions. cases can include types, wildcards, sequences,regular expressions and so forth. 5 / 17
  5. Pattern Matching DEMO characteristics • At its core Is a

    complex set of if/else expressions that lets you select from a number of alternatives. 6 / 17
  6. Pattern Matching DEMO characteristics • Guard It is useful to

    test particular conditions that cannot be tested in the pattern declaration itselft. 7 / 17
  7. Pattern Matching DEMO characteristics • Lists Pattern matching and Lists

    go hand in hand Are inmutable. Is implemented as a linked list where the head of the list is called a cons cell. cons cell is represented by the ::case class 8 / 17
  8. Pattern Matching DEMO characteristics • case classes Case classes are

    classes that get to String, hashcode, and equal methods automatically. also can be constructed without using the new keyword. By default are read-only. and the case class is inmutable. 9 / 17
  9. Pattern Matching DEMO characteristics • Nested Scala’s case classes give

    you a lot of flexibility for pattern matching, estracting values, nesting patterns, and so on. You can express a lot of logic in pattern declarations. 10 / 17
  10. Pattern Matching DEMO characteristics • Pattern matching as functions Are

    syntactic elements of the language when used with the match operator. You can also pass pattern matching as a parameter to other methods. Pattern are functions and functions are instances, pattern are instances. 11 / 17
  11. Pattern Matching DEMO characteristics • Shape abstractions Visitor pattern: It

    is a pattern that allows you to add functionality to a class hierarchy after the hierarchy is already defined. 12 / 17
  12. Pattern Matching DEMO Summary • Provide powerful declarative syntax for

    expressing complex logic. • Provide a excellent and type-safe alternative to java’s test/cast paradigm. • Used with case class and extraction provide a powerful way to traverse object hierarchies. 13 / 17