Skip to content

Instantly share code, notes, and snippets.

@kaeawc
Last active December 18, 2015 22:09
Show Gist options
  • Save kaeawc/5852951 to your computer and use it in GitHub Desktop.
Save kaeawc/5852951 to your computer and use it in GitHub Desktop.
Play! Scala code demonstrating folding left on a model that is using imperative JSON to create a JavaScript array
import java.util.Date
import play.api.libs.json._
case class Event(name:String,when:Date) extends JsSerializable
object Event extends ((String,Date) => Event) {
implicit val r = Json.reads[Event]()
implicit val w = Json.writes[Event]()
}
def foldJsList(list:List[JsSerializable]) = {
var jsList = list.foldLeft(JsArray()) {
(arr,model) => arr :+ Json.toJson(model)
}
}
foldJsList(models.Event.getCurrent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment