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
mon implementation à moi qui tue! |
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
test |
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 play.api.libs.json._ | |
val reads = (__ \ "foo").read[String] orElse Reads.pure("default string") |
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
<put your code here> |
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
case class Foo(bar: String) | |
// extends Function1 is just to workaround a limitation in Play2.1 | |
object Foo extends Function1(bar: String, Foo) { | |
implicit val fmt = Json.format[Foo] | |
} | |
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 play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
val r = ( | |
(__ \ "field1").readNullable[String] and | |
(__ \ "field2").readNullable[Int] | |
).tupled.filter(ValidationError("unexpected result")){ | |
case( Some(x), None ) => true; | |
case ( None, Some(x) ) => true; | |
case _ => false |
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
<put your code here> |
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 scala.annotation.StaticAnnotation | |
import scala.reflect.macros.Macro | |
import language.experimental.macros | |
class body(tree: Any) extends StaticAnnotation | |
trait Macros extends Macro { | |
import c.universe._ | |
def selFieldImpl = { |
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
sealed abstract trait Tree | |
case class Leaf(a: String) extends Tree | |
case class Node(l: Tree, r: Tree) extends Tree | |
implicit val treeR: Reads[Tree] = | |
__.read[Leaf].map(x => x:Tree) orElse | |
( | |
(__ \ "l").lazyRead(treeR) and (__ \ "r").lazyRead(treeR) | |
)(Node.apply _).map(x => x:Tree) | |
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 scala.reflect.macros.Context | |
import language.experimental.macros | |
trait MyTypeClass[A] { | |
def doit(a: A): A | |
} | |
object Macros { | |
def inferImplicitsImpl[A: c.WeakTypeTag](c: Context): c.Expr[MyTypeClass[A]] = { | |
import c.universe._ |
OlderNewer