From ed14aeaae471fe6d47ffc5a9b1c4841cc143ebbc Mon Sep 17 00:00:00 2001 From: Joel Cavat <jcavat@gmail.com> Date: Wed, 3 Apr 2019 15:40:20 +0200 Subject: [PATCH] Add snippet --- Query.scala | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Query.scala diff --git a/Query.scala b/Query.scala new file mode 100644 index 0000000..82a06cb --- /dev/null +++ b/Query.scala @@ -0,0 +1,75 @@ +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 -- GitLab