April 2018
Intermediate to advanced
396 pages
11h 8m
English
Let's go through the code that represents the preceding diagram and take a look at what it does. First of all, our model Person class:
case class Person(name: String, age: Int, address: String)
There is nothing special about it. Now, let's move on to the interesting part—the DataFinder class:
abstract class DataFinder[T, Y] { def find(f: T => Option[Y]): Option[Y] = try { val data = readData() val parsed = parse(data) f(parsed) } finally { cleanup() } def readData(): Array[Byte] def parse(data: Array[Byte]): T def cleanup()}
We have used generics in order to make this class usable for various types. As you can see in the preceding code, three of the methods of the DataFinder class have no implementations, but they are still referred ...
Read now
Unlock full access