September 2018
Intermediate to advanced
398 pages
9h 43m
English
In order to support variable rates, we need to change the signature of all functions that accept interestRate: Double. Instead of a double, we need a type that can represent either a constant rate or a sequence of rates.
Considering two types A and B, we previously saw how to define a type that can hold a value of type A and a value of type B. This is a product type, and we can define it using a tuple, such as ab: (A, B), or a case class, such as case class MyProduct(a: A, b: B).
On the other hand, a type that can hold either A or B is a sum type, and in Scala, we declare it using a sealed trait inheritance:
sealed trait Shapecase class Circle(diameter: Double) extends Shapecase class Rectangle(width: Double, ...
Read now
Unlock full access