Slide 1

Slide 1 text

Pattern Matching DEMO Pattern Matching Jesse Javier Cogollo Alvarez Developer by passion email: [email protected] Functional programming group September 9, 2015 1 / 17

Slide 2

Slide 2 text

Pattern Matching DEMO Content Pattern Matching DEMO 2 / 17

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Pattern Matching DEMO characteristics • Useful Provide a powerful tool for declaring business logic in a concise and maintainable way. 4 / 17

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Pattern Matching DEMO characteristics • Guard It is useful to test particular conditions that cannot be tested in the pattern declaration itselft. 7 / 17

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Pattern Matching DEMO DEMO =) 14 / 17

Slide 15

Slide 15 text

Pattern Matching DEMO Resource Beginning Scala http://www.amazon.com/Beginning-Scala-Vishal-Layka/dp/1484202333 15 / 17

Slide 16

Slide 16 text

Pattern Matching DEMO Questions 16 / 17

Slide 17

Slide 17 text

Pattern Matching DEMO Thanks !!! =) 17 / 17