I have a function that is attempting to build a JSON object containing a representation of multiple tuples that are stored in a Seq[A]
, where A
is a (Loop, Option[User])
. My code looks like so:
def loops = Action {
val page : Int = 1
val orderBy : Int = 1
val filter : String = ""
val jsonifyLoops : (Loop, Option[User]) => Map[String, String] = {
case (loop,user) =>
Map(
"name" -> loop.name,
"created_at" -> loop.createdAt.map(dateFormat.format).getOrElse(""),
"deleted_at" -> loop.deletedAt.map(dateFormat.format).getOrElse(""),
"user_name" -> user.map(_.name).getOrElse("")
)
}
Ok(toJson(Map(
"loops" -> toJson(
Loop.list( page = page, orderBy = orderBy, filter = ("%"+filter+"%") )
.items.map( jsonifyLoops )
)
)
))
}
Loops.list
produces a Page[A]
, from the helper class below:
case class Page[A](items: Seq[A], page: Int, offset: Long, total: Long) {
lazy val prev = Option(page - 1).filter(_ >= 0)
lazy val next = Option(page + 1).filter(_ => (offset + items.size) < total)
}
Thus, Loops.list(...).items
should get me a Seq[(Loop, Option[User])]
, onto which I should be able to apply a map function. I've defined my jsonifyLoops
function to have what I think is the appropriate prototype, but I must be doing something wrong, because the compiler throws me the following error:
[error] [...] Application.scala:42: type mismatch;
[error] found : (models.Loop, Option[models.User]) => Map[String,String]
[error] required: (models.Loop, Option[models.User]) => ?
[error] .items.map( jsonifyLoops )
[error] ^
What am I doing wrong?