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
| {* Example of template processing an article *} | |
| {article: Article} | |
| li class="article {article.featured ? 'featured'}" /view.root | |
| a href="/details" | |
| | {article.name} /data.name | |
| span.actions | |
| button type=button /view.editBtn | Edit | |
| button type=button /view.deleteBtn | Delete |
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 jsonquery | |
| object `package` { | |
| import dispatch.json._ | |
| implicit def jsonToSearchable(json: JsValue) = new { | |
| def \ (selector: String): Either[String, JsValue] = json match { | |
| case JsObject(map) => { | |
| (for { |
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 lambda; | |
| public interface JFunction1<T1, R> { | |
| R apply(T1 t); | |
| } |
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
| -- Un type qui sera une instance de Monad. Il s'agit d'un simple | |
| -- conteneur pour les fonctions d'un environnement vers un résultat. | |
| newtype Reader env res = Reader (env -> res) | |
| -- Une fonction qui prend un Reader et un environnement, et qui | |
| -- renvoit le résultat | |
| runReader :: Reader env res -> env -> res | |
| runReader (Reader f) e = f e | |
| -- La fameuse instance de Monad. return ignore son environnement, |
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 { | |
| val index = Action { implicit request => | |
| Ok(views.html.index()) | |
| } | |
| val show = Action { implicit request => | |
| Ok(views.html.show("42")) | |
| } | |
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 show(article: Article) = Action { | |
| Ok(views.html.article(article)) | |
| } |
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 with PathLang { | |
| def index = Ok(html.index()) | |
| } |
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
| scala> trait Foo[+A] | |
| defined trait Foo | |
| scala> implicit object intFoo extends Foo[Int] | |
| defined module intFoo | |
| scala> implicit def traversableFoo[F[_], A](implicit bf: collection.generic.CanBuildFrom[F[_], A, F[A]], aFoo: Foo[A]) = new Foo[F[A]] {} | |
| traversableFoo: [F[_], A](implicit bf: scala.collection.generic.CanBuildFrom[F[_],A,F[A]], implicit aFoo: Foo[A])java.lang.Object with Foo[F[A]] | |
| scala> implicitly[Foo[List[Int]]] |
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
| // --- Definition of a query string binder for type A using a Mapping[A] | |
| object Binders { | |
| implicit def mappingBinder[A](implicit mapping: Mapping[A]) = new QueryStringBindable[A] { | |
| override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]] = { | |
| val data = for { | |
| (k, ps) <- params | |
| if k startsWith key | |
| p <- ps.headOption | |
| } yield (k.drop(key.length + 1), p) |
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 Contact(name: String, email: String) |