3

Click here to load reader

Scala for the web Lightning Talk

Embed Size (px)

DESCRIPTION

Nathan Hamblen gives a lightning talk about Scala

Citation preview

Page 1: Scala for the web Lightning Talk

Scala for the Web Will it blend? def ol(items: Seq[String]) = <ol> { items.map { s => <li> { s } </li> } } </ol>

Scala is hybrid. λ + ☃ = ?

Lift Ajax.scala // create an ajax select box def doSelect(msg: NodeSeq) = ajaxSelect((1 to 50).toList.map { i => (i.toString, i.toString) }, Full(1.toString), { v => DisplayMessage(msgName, bind("sel", msg, "number" -> Text(v)), 5 seconds, 1 second) }) // bind the view to the functionality bind("select" -> doSelect _, ... ajax.html

Page 2: Scala for the web Lightning Talk

<ajax:select> You selected <sel:number></sel:number> From the select box. </ajax:select>

Scalate • Mustache • Scaml • Jade • SSP

XML literals. Seriously. val myDiv = <div>Yo</div>

Scalatra class MyScalatraFilter extends ScalatraFilter { get("/") { <html> <body> <h1>Hello, world!</h1> </body> </html> } } def ol(items: Seq[String]) = <ol> { items.map { s => <li> { s } </li> } } </ol>

Unfiltered import unfiltered.request._ import unfiltered.response._ val echo = unfiltered.filter.Planify {

Page 3: Scala for the web Lightning Talk

case Path(Seg(p :: Nil)) => ResponseString(p) } unfiltered.jetty.Http.anylocal.filter(echo).run() object Stream extends unfiltered.netty.async.Plan with ServerErrorResponse { val ChunkedMp3 = unfiltered.response.Connection(HttpHeaders.Values.CLOSE) ~> TransferEncoding(HttpHeaders.Values.CHUNKED) ~> ContentType("audio/mp3") val listeners = new DefaultChannelGroup def intent = { case req => val initial = req.underlying.defaultResponse(ChunkedMp3) val ch = req.underlying.event.getChannel ch.write(initial).addListener { () => listeners.add(ch) } } ...

Scala for the Web Yes, it blends! http://meetup.com/ny-scala