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
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/ByNameParameter.scala
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,16 @@ object ByNameParameter
18
18
19
19
/** `() => Int` is a Function type that takes a `Unit` type. `Unit` is known as `void` to a Java programmer. The function returns an `Int`. You can place this as a method parameter so that you can you use it as a block, but still it doesn't look quite right:
valy= calc { () ⇒//Having explicitly declaring that Unit is a parameter with ()
30
+
valy= calc { () =>//Having explicitly declaring that Unit is a parameter with ()
31
31
14+15
32
32
}
33
33
@@ -36,13 +36,13 @@ object ByNameParameter
36
36
37
37
/** A by-name parameter does the same thing as the previous koan but there is no need to explicitly handle `Unit` or `()`. This is used extensively in Scala to create blocks:
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/Classes.scala
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ object Classes extends AnyFlatSpec with Matchers with org.scalaexercises.definit
17
17
* Here is a class definition which defines a class Point:
18
18
*
19
19
* {{{
20
-
* class Point(x: Int, y: Int) {
20
+
* class Point(x: Int, y: Int) = {
21
21
* override def toString(): String = "(" + x + ", " + y + ")"
22
22
* }
23
23
* }}}
@@ -29,7 +29,7 @@ object Classes extends AnyFlatSpec with Matchers with org.scalaexercises.definit
29
29
*
30
30
* {{{
31
31
* object Classes {
32
-
* def main(args: Array[String]) {
32
+
* def main(args: Array[String]) = {
33
33
* val pt = new Point(1, 2)
34
34
* println(pt)
35
35
* }
@@ -41,7 +41,7 @@ object Classes extends AnyFlatSpec with Matchers with org.scalaexercises.definit
41
41
* This also demonstrates the use of value parameters in `ClassWithValParameter(val name: String)`, which automatically creates an internal property `val name: String` in the class:
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/EmptyValues.scala
+10-16Lines changed: 10 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -36,69 +36,63 @@ object EmptyValues extends AnyFlatSpec with Matchers with org.scalaexercises.def
36
36
*
37
37
* An empty list can be represented by another nothing value: `Nil`
38
38
*/
39
-
defemptyValuesEmptyValues(res0: Boolean) {
39
+
defemptyValuesEmptyValues(res0: Boolean) =
40
40
List() ===Nil shouldBe res0
41
-
}
42
41
43
42
/** [[http://www.scala-lang.org/api/current/index.html#scala.None None]] is the counterpart to [[http://www.scala-lang.org/api/current/index.html#scala.Some Some]], used when you're using Scala's [[http://www.scala-lang.org/api/current/index.html#scala.Option Option]] class to help avoid `null` references.
44
43
*
45
44
* `None` equals `None`:
46
45
*/
47
-
defavoidingNullEmptyValues(res0: Boolean) {
46
+
defavoidingNullEmptyValues(res0: Boolean) =
48
47
None===None shouldBe res0
49
-
}
50
48
51
49
/** `None` should be identical to `None`:
52
50
*/
53
-
defidenticalNoneEmptyValues(res0: Boolean) {
51
+
defidenticalNoneEmptyValues(res0: Boolean) =
54
52
None eq None shouldBe res0
55
-
}
56
53
57
54
/** `None` can be converted to a String:
58
55
*/
59
-
defnoneToStringEmptyValues(res0: String) {
56
+
defnoneToStringEmptyValues(res0: String) =
60
57
assert(None.toString === res0)
61
-
}
62
58
63
59
/** `None` can be converted to an empty list:
64
60
*/
65
-
defnoneToListEmptyValues(res0: Boolean) {
61
+
defnoneToListEmptyValues(res0: Boolean) =
66
62
None.toList ===Nil shouldBe res0
67
-
}
68
63
69
64
/** `None` is considered empty:
70
65
*/
71
-
defnoneAsEmptyEmptyValues(res0: Boolean) {
66
+
defnoneAsEmptyEmptyValues(res0: Boolean) =
72
67
assert(None.isEmpty === res0)
73
-
}
74
68
75
69
/** `None` can be cast to `Any`, `AnyRef` or `AnyVal`:
0 commit comments