Guest User

Untitled

a guest
May 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.60 KB | None | 0 0
  1. sealed abstract class LogRow
  2. case class SemasioRow(x: String, y: Int) extends LogRow
  3. case class TectonicRow(y: String, z: Float) extends LogRow
  4.  
  5. // Here comes the factory
  6. object LogRow {
  7.   def apply[T](s: String)(implicit m: Manifest[T]) = m match {
  8.     case x: Manifest[SemasioRow] => new SemasioRow("xpto", 1)    // It's technically possible to make this a call to a companion SemasioRow object that decodes a string
  9.     case x: Manifest[TectonicRow] => new TectonicRow("xpto", 2)
  10.   }
  11. }
  12.  
  13. object LogReader{
  14.   def apply(filename: String): List[LogRow] = {
  15.     List(LogRow[SemasioRow]("hello"))
  16.   }
  17. }
Add Comment
Please, Sign In to add comment