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._ | |
| val pattern = "yyyy-MM-dd'T'HH:mm:ssz" | |
| implicit val dateFormat = Format[DateTime]( | |
| Reads.jodaDateReads(pattern), | |
| Writes.jodaDateWrites(pattern) | |
| ) | |
| Json.toJson(new DateTime("1952-03-11")) | |
| // => "1952-03-11T00:00:00PDT" |
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 sort[T <% Ordered[T]](seq: Seq[T]): Seq[T] = seq match { | |
| case Seq() => Seq() | |
| case x +: xs => | |
| val (before, after) = xs partition (_ < x) | |
| sort(before) ++ sort(x +: after) | |
| } | |
| sort(IndexedSeq("Greg", "Eishay", "Andrew")) | |
| // => List(Andrew, Eishay, Greg) |
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 reflect.ClassTag | |
| import reflect.ClassTag | |
| def filterBy[T: ClassTag](seq: Seq[Any]) = seq collect { | |
| case x: T => x | |
| } | |
| filterBy[String](Seq(1, "two", "three")) | |
| // => Seq[String] = List(two, three) |
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 (x, y): (Int, Int) = ("a", "b") | |
| :7: error: type mismatch; | |
| found : String("a") | |
| required: Int | |
| val (x, y): (Int, Int) = ("a", "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
| val (a, b): (Int, Int) = ("a", "b") | |
| :7: warning: non variable type-argument Int in type pattern (Int, Int) is unchecked since it is eliminated by erasure | |
| val (a, b): (Int, Int) = ("a", "b") | |
| ^ | |
| java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer | |
| ... |
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
| // Get a file within the .fortytwo folder in the user's home directory | |
| def getUserFile(filename: String): File = | |
| new File(Seq(System.getProperty("user.home"), ".fortytwo", filename).mkString(File.separator)) | |
| override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode) = { | |
| val localConfig = Configuration(ConfigFactory.parseFile(getUserFile("local.conf"))) | |
| super.onLoadConfig(config ++ localConfig, path, classloader, mode) | |
| } |
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.Play.current | |
| def coolFeatureEnabled = current.configuration.getBoolean("coolFeatureEnabled").getOrElse(false) | |
| def myAction() = Action { request => | |
| if (coolFeatureEnabled) { | |
| // do cool stuff | |
| } else { | |
| // do regular stuff | |
| } | |
| } |
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
| class ActorBuilderImpl extends ActorBuilder { | |
| def apply(system: ActorSystem, provider: Provider[_ <: Actor]): ActorRef = | |
| system.actorOf(Props { provider.get }) | |
| } |