Last active
December 18, 2015 22:09
-
-
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
This file contains 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
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