Jyoti Sachdeva explains what extractors are in Scala and why they’re useful:
An
extractor
is an object that has anunapply
method. It takes an object as an input and gives back arguments. Custom extractors are created using the unapply method. Theunapply
method is calledextractor
because it takes an element of the same set and extracts some of its parts,apply
method also called injection acts as a constructor, takes some arguments and yields an element of a given set.
Click through for explanatory examples.