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