Scala Extractor is defined as an object which has a method named unapply as one of its part. Extractors can be utilized in Pattern Matching. The unapply method will be executed spontaneously, While comparing the Object of an Extractor in Pattern Matching.
Below is the example of Extractor with pattern matching.
5.0 The value is: 1.0
In above example, object name is GFG also we are using unapply method and applying case class with match expression.
30 30 is bigger two times than 15
When comparing an extractor object using the match statement the unapply method will be automatically executed.
Note: A Case class already has an Extractor in it so, it can be utilized spontaneously with Pattern Matching.
- Scala Extractors
- Scala | Partially Applied functions
- Scala Keywords
- Scala Map size() method with example
- Scala Iterator addString() method with example
- Scala | Functions Call-by-Name
- Scala | Type Inference
- Parameterless Method in Scala
- Introduction to Scala
- Scala | Decision Making (if, if-else, Nested if-else, if-else if)
- The Factory Pattern in Scala
- Scala | Loops(while, do..while, for, nested loops)
- Scala | Closures
- Scala Iterator size() method with example
- Scala List isEmpty Operation with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.