Skip to content
Snippets Groups Projects
Commit ed14aeaa authored by Joel Cavat's avatar Joel Cavat
Browse files

Add snippet

parent a3474315
No related branches found
No related tags found
No related merge requests found
case class Livre(id_livre: String, titre: String, id_theme: Int)
case class Theme(id_theme: Int, intitule: String)
case class Personne(id_personne: Int, prenom: String, nom: String, email: String, date_naissance: Int, localite: String)
case class Emprunt(id_personne: Int, id_livre: String, date_emprunt: Int, date_retour: Int, date_echeance: Int)
val personnes = Set(
Personne(23,"Aurelia","Racloz","a.racloz@gnail.cn",19990501,"Bulle"),
Personne(18,"Stephane","Ischi","st.ischi@tartempion.net",19801003,"Lausanne"),
Personne(14,"Danielle","Zuffret","zuffret@commerce.cm",19710302,"Penthalaz"),
Personne(16,"Naim","Daiz","naim.daiz@gnail.cn",19930505,"Lausanne"),
Personne(29,"Jerome","Doutaz","jerome@doutaz.ch",20011201,"Genève")
)
val livres = Set(
Livre("2-X-4","Les Acqueducs",1),
Livre("5-X-1","Python pour les nuls",2),
Livre("7-X-3","Base de donnees avancee",2)
)
val themes = Set(
Theme(1,"Architecture"),
Theme(2,"Informatique"),
Theme(3,"Mathématique")
)
val emprunts = Set(
Emprunt(23,"2-X-4",20150101,20150128,20150201),
Emprunt(18,"2-X-4",20150305,20150401,20150405),
Emprunt(18,"5-X-1",20160203,20160301,20160305),
Emprunt(16,"7-X-3",20150718,20150814,20150818),
Emprunt(29,"5-X-1",20151222,20160118,20160122),
Emprunt(23,"7-X-3",20150117,30000101,20150217),
Emprunt(29,"2-X-4",20150521,20150617,20150621),
Emprunt(16,"2-X-4",20150730,20150826,20150830),
Emprunt(16,"5-X-1",20160321,30000101,20160421),
Emprunt(29,"7-X-3",20150506,20150602,20150606)
)
case class User(login: String,
age: Int,
email: String,
favoriteFood: List[String])
val users = List(
User("michael", 28, "mike@hepia.com", List("sushi")),
User("marc", 17, "marc@test.ch", List("pizza", "kebab")),
User("stephanie", 16, "steph@nie.ch", List("thai", "kebab")),
User("paul", 46, "paul1@test.ch", List("pizza", "kebab", "hotdog")),
User("pauline", 27, "pauline@line.ch", List("sushi", "thai"))
)
def lookup(login: String): Option[User] =
users.find( u => u.login == login )
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.util.{Success, Failure}
def lookup(login: String): Future[User] = Future {
Thread.sleep(1000)
users.find( u => u.login == login ).get
}
import scala.concurrent.{ Future, Promise }
val p = Promise[Int]()
val f = p.future
f.foreach( println )
p success 44
p completeWith Future { Thread.sleep(1000); 44 }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment