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
| trait Functor[F[_]] { | |
| def fmap[A, B](f: A => B): F[A] => F[B] | |
| } |
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
| /** | |
| * data (f :+: g) a = Inl (f a) | Inr (g a) | |
| */ | |
| sealed trait Coproduct[F[+_], G[+_], A] | |
| case class Inl[F[+_], G[+_], A](a: F[A]) extends Coproduct[F, G, A] | |
| case class Inr[F[+_], G[+_], A](a: G[A]) extends Coproduct[F, G, A] | |
| trait :+:[F[+_], G[+_]] { | |
| type Apply[A] = Coproduct[F, G, 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
| object Ok { | |
| trait Foo[A] | |
| case class Bar(x: Int) | |
| object Bar { | |
| implicit class BarOps(bar: Foo[Bar]) { | |
| val ok = "ok" | |
| } | |
| } | |
| def usage(bar: Foo[Bar]) = bar.ok // Ok, the implicit conversion is found in the Bar companion object |
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
| // Some data type definitions: the usual (and boring) zoo class hierarchy | |
| abstract class Animal { } | |
| abstract class Mammal extends Animal { } | |
| class Giraffe extends Mammal { } | |
| class Zebra extends Mammal { | |
| num stripeCount; | |
| Zebra(num stripeCount) { |
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 Main extends App { | |
| // You can retrieve the application configuration from any place | |
| val configuration = Configuration("conf/my-app.conf") | |
| // You instantiate your controllers with their required configuration | |
| val application = new MyAbstractController(configuration) with SomeEventualMixin | |
| // You pass your controllers as parameters to a router factory | |
| val router = Router("conf/routes", application) |
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 controllers; | |
| import play.mvc.Controller; | |
| import play.libs.Json; | |
| import static controllers.Render.*; | |
| import static play.mvc.Http.MimeTypes; | |
| public class Application extends Controller { |
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
| val client = new NingWSClient(new NingAsyncHttpClientConfigBuilder(DefaultWSClientConfig()).build()) | |
| client.url("…").get().foreach { response => | |
| … | |
| client.close() | |
| } |
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
| /* A basic implementation of bar */ | |
| define(function () { | |
| return { | |
| plop: function () { alert('bar implementation'); } | |
| } | |
| }); |
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 taggedResult(request: RequestHeader, tag: String)(result: => Result): Result = | |
| request.headers.get(IF_NONE_MATCH) match { | |
| case Some(t) if t == tag => NotModified | |
| case _ => result.withHeaders(ETAG -> tag) | |
| } | |
| // Example of use: | |
| val javascriptRoutes = { | |
| val router = | |
| JavaScriptReverseRouter("routes", None, hostname, |
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 slick.lifted.TupleShape | |
| import slick.driver.H2Driver.api._ | |
| import scala.concurrent.Await | |
| import scala.concurrent.duration.DurationInt | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| object Example { | |
| val db = Database.forConfig("db") |