This file contains hidden or 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
def index = Action { | |
import Json._ | |
//val jsObj = Json( "alpha" \: 123 ++ "beta" \: "chboing" ) | |
val data = JsObject( | |
Seq(("newspaper", JsObject(Seq( | |
("url", JsString("http://nytimes.com")), | |
("attributes", JsObject(Seq( | |
("name", JsString("nytimes")), | |
("country", JsString("US")), |
This file contains hidden or 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
object Application extends Controller { | |
def index = Action { | |
import RichJson._ | |
// Classic Play20 JSon API | |
val oldVersion = | |
JsObject(Seq( | |
("key1", JsObject(Seq( | |
("key11", JsString("alpha11")), |
This file contains hidden or 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
def mkString[E](start: String, sep: String, end: String): Iteratee[E, String] = { | |
def step(s: String, isFirst: Boolean)(input: Input[E]): Iteratee[E, String] = { | |
input match { | |
case Input.EOF => Done(s + end, Input.EOF) | |
case Input.Empty => Cont(step(s, isFirst)) | |
case Input.El(e) => { val s1 = if(isFirst) { s + e.toString } else { s + sep + e.toString }; Cont[E, String](i => step(s1, false)(i)) } | |
} |
This file contains hidden or 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
"copy file" in { | |
var i = 0 | |
val fileGenerator = Enumerator.fromCallback( () => | |
if(i<1000){ i+=1; Future.successful(Some((new java.util.Date).getTime.toString + "\n")) } else Future(None) | |
) | |
val f = FileChannel("/tmp/testwrite.txt").delete.writing.create | |
val f2 = FileChannel("/tmp/testwrite2.txt").delete.writing.create | |
fileGenerator // generates data |
This file contains hidden or 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
case class ~[A, B](a: A, b: B) | |
package alpha { | |
trait AlphaReader[A] { | |
def read(s: String): A | |
} | |
object AlphaReader{ | |
def apply[A](f: String => A): AlphaReader[A] = new AlphaReader[A] { |
This file contains hidden or 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 play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
import scala.util.control.Exception._ | |
import java.lang.NumberFormatException | |
import play.api.data.validation.ValidationError | |
implicit val bigDecReads = Reads[java.math.BigDecimal]( js => js match { | |
case JsString(s) => | |
catching(classOf[NumberFormatException]) | |
.opt( JsSuccess(new java.math.BigDecimal(s)) ) |
This file contains hidden or 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
package alpha { | |
trait AlphaReader[A] { | |
def read(s: String): A | |
} | |
object AlphaReader{ | |
def apply[A](f: String => A): AlphaReader[A] = new AlphaReader[A] { | |
def read(s: String) = f(s) |
This file contains hidden or 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
mon implementation à moi qui tue! |
This file contains hidden or 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
My awesome question |
This file contains hidden or 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
My awesome question |
OlderNewer