Created
February 4, 2013 10:55
-
-
Save YoEight/4706119 to your computer and use it in GitHub Desktop.
Reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Toto { | |
case class SummaryRow(msg: String, count: Int, rate: Float) | |
case class BreakDownRow(sup: String, amount: Int) | |
case class SegmentedRow(segment: String, length: Int) | |
type Id[A] = A | |
trait Reporting[A, B[_]] { | |
val parser: Parser[A] | |
def foo(xs: List[A]): B[A] | |
def makeReport(sql: SimpleSql)(implicit connection: Connection): B[A] = | |
foo(sql.as(parser *)) | |
} | |
object Reporting { | |
def apply[A, B[_]](sql: SimpleSql)(implicit R: Reporting[A, B], C: Connection): B[A] = R.makeReport(sql) | |
} | |
trait Parser[A] { | |
def parser: RowParser[A] | |
} | |
object SummaryRow { | |
implicit val reporting = new Reporting[SummaryRow, Id]{ | |
def foo(xs: List[SummaryRow]) = xs match { | |
case x :: _ => x | |
case _ => sys.error("") | |
} | |
} | |
} | |
object BreakDownRow { | |
implicit val reporting = new Reporting[BreakDownRow]{ | |
def foo(xs: List[BreakDownRow]) = xs | |
} | |
} | |
object SegmentedRow { | |
implicit val reporting = new Reporting[SegmentedRow]{ | |
def foo(xs: List[SegmentedRow]) = xs | |
} | |
} | |
Reporting[SummaryRow, Id]("") | |
Reporting[BreakDownRow, List]("") | |
Reporting[SegmentedRow, List]("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment