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 Contexts.myDbOperationContext | |
concurrent.Future { | |
// Nejaky blokujici kod pristupujici k databazi | |
} |
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
play { | |
my-db-context { | |
fork-join-executor { | |
parallelism-factor = 1.0 | |
parallelism-max = 200 | |
} | |
} | |
} |
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
object Contexts { | |
implicit val myDbOperationContext: ExecutionContext = | |
Akka.system.dispatchers.lookup("my-db-context") | |
} |
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.concurrent.Execution.Implicits._ | |
def someAsyncAction = Action { | |
Async { | |
WS.get("http://www.someservice.com").get().map { | |
response => | |
Ok("Response code: " + response.status) | |
} | |
} | |
} |
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
package dojo | |
import java.net.URL | |
import java.io.File | |
import scala.io.Source | |
import java.io.InputStream | |
import scala.util.Try | |
import scala.util.Success | |
trait Resource[R] { |
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 Person(firstName: String, lastName: String, male: Boolean) | |
val people = List( | |
Person("Veronika", "Skalova", false), | |
Person("Jana", "Heroutova", false), | |
Person("Miroslav", "Klepis", true)) | |
for (Person(_, lastName, false) <- people) yield "Pani " + lastName | |
// Pani Skalova, Pani Heroutova |
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
val myTuple = (1, 2) | |
val (x, y) = myTuple // (x, y) je constructor pattern pro tuple | |
println(x) // 1 | |
val addOperation = Add(Number(1), Add(Number(2), Number(3))) | |
val Add(Number(_), secondOperand @ Add(_, b)) = addOperation | |
// Add(Number(_), secondOperand @ Add(_, b)) je constructor pattern | |
// s vnořenými constructor patterny pro první a druhý parametr, | |
// b je matchováno variable patternem a match. hodnota je do něj uložena | |
println(b) // Number(3) |
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
// Pattern matching for defining partial functions | |
val numToRoman: PartialFunction[Int, String] = { | |
case 4 => "IV" | |
case 5 => "V" | |
case 6 => "VI" | |
} | |
println(numToRoman.isDefinedAt(7)) // 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
try { | |
processFile("input.txt") | |
} catch { | |
case ex: FileNotFoundException => println("Missing file exception: " + | |
ex.getMessage()) | |
case ex: IOException => println("IO exception: " + ex.getMessage()) | |
} |
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
val n: Any = -20 | |
n match { | |
case i : Int if (i > 0) => "positive int" | |
case s : String if (s.length() > 0) => "non-empty string" | |
} |