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
/** | |
* Dumps (possibly large) database table to SQL file or more files | |
* according to MaxRecordsPerFile parameter. | |
* @author Radek Beran | |
*/ | |
import java.io._ | |
import java.sql._ | |
// --- SCRIPT PARAMETERS --- | |
val DriverName = "com.mysql.jdbc.Driver" |
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 parSeq: ParSeq[Int] = List(3, 4, 5).par |
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
// Posčítání cen automobilů, jejichž výrobcem je Porsche: | |
case class CarModel(carMaker: CarMaker.Value, name: String, price: Option[Int]) | |
val models: List[CarModel] = List(...) | |
models.view.filter(_.carMaker == CarMaker.Porsche).map(_.price.getOrElse(0)).sum |
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 parSeq: ParSeq[Int] = List(3, 4, 5).par |
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
(for { | |
m <- models.view // vytvoří non-strict view pamatující si lazy vykonávané operace | |
if m.carMaker == CarMaker.Porsche | |
price <- m.price // transformace na kolekci obsahující ceny | |
} yield price).sum |
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
// Posčítání cen automobilů, jejichž výrobcem je Porsche: | |
case class CarModel(carMaker: CarMaker.Value, name: String, | |
price: Option[Int]) | |
val models: List[CarModel] = ... | |
models.view.filter(_.carMaker == CarMaker.Porsche).map( | |
_.price.getOrElse(0)).sum |
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
(for { | |
m <- models.view // non-strict view pamatující si vykonávané operace | |
if m.carMaker == CarMaker.Porsche | |
price <- m.price // transformace na kolekci obsahující ceny | |
} yield price).sum |
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(name: String, age: Int, programmer: Boolean) |
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
abstract class Person(name: String, birthDate: java.util.Date) | |
// nevhodny mutable typ java.util.Date | |
case class Man(var name: String, birthDate: java.util.Date, | |
impertinent: Boolean) extends Person(name, birthDate) | |
case class Woman(private val name: String, birthDate: java.util.Date, | |
quarrelsome: Boolean) extends Person(name, birthDate) | |
class XMan(name: String, birthDate: java.util.Date, impertinent: Boolean, | |
ability: String) extends Man(name, birthDate, impertinent) |
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 birthDate = new java.util.Date() | |
//> birthDate : java.util.Date = Sat Mar 16 19:55:08 CET 2013 | |
val man = Man("Johnny", birthDate, true) | |
//> man : app.Man = Man(Johnny,Sat Mar 16 19:55:08 CET 2013, true) | |
val woman = Woman("Jessica", birthDate, true) | |
//> woman : obj.Woman = Woman(Jessica,Sat Mar 16 19:55:08 CET 2013,true) | |
println(woman) // vola toString() | |
//> Woman(Jessica,Sat Mar 16 19:55:08 CET 2013,true) | |
println(Woman("Jessica", birthDate, true) == Woman("Jessica", birthDate, true)) | |
// vola equals |
OlderNewer