You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`do { println(x); x += 1} while (x < 5)`| boucle do while. |
57
57
|`import scala.util.control.Breaks._`<br>`breakable {`<br>` for (x <- xs) {`<br>` if (Math.random < 0.1) break`<br>` }`<br>`}`| break. ([transparents](http://www.slideshare.net/Odersky/fosdem-2009-1013261/21)) |
58
-
|`for (x <- xs if x%2 == 0) yield x*10`_est équivalent à_ <br>`xs.filter(_%2 == 0).map(_*10)`|compréhension avec for: filter/map |
59
-
|`for ((x,y) <- xs zip ys) yield x*y`_est équivalent à_ <br>`(xs zip ys) map { case (x,y) => x*y }`|compréhension avec for : liaison déstructurée |
60
-
|`for (x <- xs; y <- ys) yield x*y`_est équivalent à_ <br>`xs flatMap {x => ys map {y => x*y}}`|compréhension avec for : produit cartésien. |
61
-
|`for (x <- xs; y <- ys) {`<br> `println("%d/%d = %.1f".format(x,y, x*y))`<br>`}`|compréhension avec for : à la manière impérative <br>[sprintf-style](http://java.sun.com/javase/6/docs/api/java/util/Formatter.html#syntax)|
62
-
|`for (i <- 1 to 5) {`<br> `println(i)`<br>`}`|compréhension avec for : itère jusqu'à la borne supérieure comprise. |
63
-
|`for (i <- 1 until 5) {`<br> `println(i)`<br>`}`|compréhension avec for : itère jusqu'à la borne supérieure non comprise. |
| <spanclass="label success">Good</span> `(xs zip ys) map { case (x,y) => x*y }`<br> <spanclass="label important">Bad</span> `(xs zip ys) map( (x,y) => x*y )`| cas d’utilisation d’une fonction utilisée avec un "pattern matching". |
66
66
| <spanclass="label important">Bad</span><br>`val v42 = 42`<br>`Some(3) match {`<br>` case Some(v42) => println("42")`<br>` case _ => println("Not 42")`<br>`}`| "v42" est interprété comme un nom ayant n’importe quelle valeur de type Int, donc "42" est affiché. |
0 commit comments