【发布时间】:2013-10-03 18:24:00
【问题描述】:
当我在 Play 中阅读时! docs 我找到了一种将结果解析为 List[(String, String)]
的方法像这样:
// Create an SQL query
val selectCountries = SQL("Select * from Country")
// Transform the resulting Stream[Row] as a List[(String,String)]
val countries = selectCountries().map(row =>
row[String]("code") -> row[String]("name")
).toList
我想这样做,但我的元组将包含更多数据。
我是这样做的:
val getObjects = SQL("SELECT a, b, c, d, e, f, g FROM table")
val objects = getObjects().map(row =>
row[Long]("a") -> row[Long]("b") -> row[Long]("c") -> row[String]("d") -> row[Long]("e") -> row[Long]("f") -> row[String]("g")).toList
我得到的每个元组都将采用这种格式,当然,这就是我在上面的代码中要求的:
((((((Long, Long), Long), String), Long), Long), String)
但我想要这个:
(Long, Long, Long, String, Long, Long, String)
我要问的是我应该如何解析结果以生成一个像上面最后一个一样的元组。我想像他们在 List[(String, String)] 文档中所做的那样做,但需要更多数据。
谢谢
【问题讨论】:
标签: scala playframework tuples scala-collections