unapply

Companion Object in Scala

Reading Time: 4 minutes Companion Object is a singleton object of a class sharing same name and same source file.The class is called a Companion Class.For instance, we have a class name Person in Person.scala and an singleton object Person in the same file: In this file the object Person is a companion object and class Person is a companion class. Benefits of Companion Object Companion Objects in Scala gives many benefits.First, companion object and class can access each Continue Reading

Scala Extractors

Scala: Extractors and Pattern Matching

Reading Time: 3 minutes An extractor in Scala is an object which has an unapply method as one of its members. Often, the extractor object also defines a method apply for building values, but this is not required. An apply method is like a constructor which takes arguments and creates an object, the unapply method takes an object and tries to give back the arguments. The unapply method reverses the construction procedure of the Continue Reading