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
/** `() => 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.
9
+
/** `() => 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:
@@ -24,7 +24,7 @@ object ByNameParameter extends FlatSpec with Matchers with org.scalaexercises.de
24
24
y should be(res0)
25
25
}
26
26
27
-
/** 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.
27
+
/** 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/CaseClasses.scala
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
8
8
9
9
/** Scala supports the notion of ''case classes''. Case classes are regular classes which export their constructor parameters and which provide a recursive decomposition mechanism via pattern matching.
10
10
*
11
-
* Here is an example for a class hierarchy which consists of an abstract super class `Term` and three concrete case classes `Var`, `Fun`, and `App`.
11
+
* Here is an example for a class hierarchy which consists of an abstract superclass `Term` and three concrete case classes `Var`, `Fun`, and `App`:
12
12
*
13
13
* {{{
14
14
* abstract class Term
@@ -32,7 +32,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
32
32
* println(x.name)
33
33
* }}}
34
34
*
35
-
* For every case class the Scala compiler generates `equals` method which implements structural equality and a`toString` method. For instance:
35
+
* For every case class the Scala compiler generates an `equals` method which implements structural equality and a`toString` method. For instance,
36
36
*
37
37
* {{{
38
38
* val x1 = Var("x")
@@ -218,7 +218,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/Classes.scala
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ object Classes extends FlatSpec with Matchers with org.scalaexercises.definition
14
14
* override def toString(): String = "(" + x + ", " + y + ")"
15
15
* }
16
16
* }}}
17
-
* The class defines two variables `x` and `y` and one method: `toString`.
17
+
* The class defines two variables `x` and `y` and one method `toString`.
18
18
*
19
19
* Classes in Scala are parameterized with constructor arguments. The code above defines two constructor arguments, `x` and `y`; they are both visible in the whole body of the class. In our example they are used to implement `toString`.
20
20
*
@@ -31,7 +31,7 @@ object Classes extends FlatSpec with Matchers with org.scalaexercises.definition
31
31
*
32
32
* The program defines an executable application `Classes` in the form of a top-level singleton object with a `main` method. The `main` method creates a new `Point` and stores it in value `pt`.
33
33
*
34
-
* 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.
34
+
* 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
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ object EmptyValues extends FlatSpec with Matchers with org.scalaexercises.defini
17
17
*
18
18
* ==Nothing==
19
19
*
20
-
* [[http://www.scala-lang.org/api/current/index.html#scala.Nothing Nothing]] is a trait that is guaranteed to have _zero_ instances. It is a subtype of all other types. It has two main reasons for existing: to provide a return type for methods that **never** return normally (i.e. a method that always throws an exception). The other reason is to provide a type for Nil (explained below).
20
+
* [[http://www.scala-lang.org/api/current/index.html#scala.Nothing Nothing]] is a trait that is guaranteed to have zero instances. It is a subtype of all other types. It has two main reasons for existing: to provide a return type for methods that never return normally (i.e. a method that always throws an exception). The other reason is to provide a type for Nil (explained below).
21
21
*
22
22
* ==Unit==
23
23
*
@@ -47,41 +47,41 @@ object EmptyValues extends FlatSpec with Matchers with org.scalaexercises.defini
47
47
None eq None shouldBe res0
48
48
}
49
49
50
-
/** `None` can be converted to a *String*:
50
+
/** `None` can be converted to a String:
51
51
*/
52
52
defnoneToStringEmptyValues(res0: String) {
53
53
assert(None.toString === res0)
54
54
}
55
55
56
-
/** `None` can be converted to an empty list
56
+
/** `None` can be converted to an empty list:
57
57
*/
58
58
defnoneToListEmptyValues(res0: Boolean) {
59
59
None.toList ===Nil shouldBe res0
60
60
}
61
61
62
-
/** `None` is considered empty
62
+
/** `None` is considered empty:
63
63
*/
64
64
defnoneAsEmptyEmptyValues(res0: Boolean) {
65
65
assert(None.isEmpty === res0)
66
66
}
67
67
68
-
/** `None` can be cast `Any`, `AnyRef` or `AnyVal`
68
+
/** `None` can be cast to `Any`, `AnyRef` or `AnyVal`:
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/Extractors.scala
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
25
25
*
26
26
* There are two syntactic conventions at work here:
27
27
*
28
-
* - The pattern `case Twice(n)` will cause an invocation of `Twice.unapply`, which is used to match even number; the return value of the `unapply` signals whether the argument has matched or not, and any sub-values that can be used for further matching. Here, the sub-value is `z/2`
29
-
* - The `apply` method is not necessary for pattern matching. It is only used to mimick a constructor. `val x = Twice(21)` expands to `val x = Twice.apply(21)`.
28
+
* - The pattern `case Twice(n)` will cause an invocation of `Twice.unapply`, which is used to match even number; the return value of the `unapply` signals whether the argument has matched or not, and any sub-values that can be used for further matching. Here, the sub-value is `z/2`
29
+
* - The `apply` method is not necessary for pattern matching. It is only used to mimick a constructor. `val x = Twice(21)` expands to `val x = Twice.apply(21)`.
30
30
*
31
31
* The code in the preceding example would be expanded as follows:
32
32
*
@@ -38,9 +38,9 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
38
38
* }}}
39
39
* The return type of an `unapply` should be chosen as follows:
40
40
*
41
-
* - If it is just a test, return a `Boolean`. For instance `case even()`
42
-
* - If it returns a single sub-value of type `T`, return a `Option[T]`
43
-
* - If you want to return several sub-values `T1,...,Tn`, group them in an optional tuple `Option[(T1,...,Tn)]`.
41
+
* - If it is just a test, return a `Boolean`. For instance `case even()`
42
+
* - If it returns a single sub-value of type `T`, return a `Option[T]`
43
+
* - If you want to return several sub-values `T1,...,Tn`, group them in an optional tuple `Option[(T1,...,Tn)]`.
44
44
*
45
45
* Sometimes, the number of sub-values is fixed and we would like to return a sequence. For this reason, you can also define patterns through `unapplySeq`. The last sub-value type `Tn` has to be `Seq[S]`. This mechanism is used for instance in pattern `case List(x1, ..., xn)`.
46
46
*
@@ -76,7 +76,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
76
76
d should be(res3)
77
77
}
78
78
79
-
/**Of course an extractor can be used in pattern matching...
79
+
/**An extractor can also be used in pattern matching:
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/HigherOrderFunctions.scala
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
9
9
10
10
/** Meet lambda. Scala provides a relatively lightweight syntax for defining anonymous functions. Anonymous functions in source code are called function literals and at run time, function literals are instantiated into objects called function values.
11
11
*
12
-
* Scala supports first-class functions, which means you can express functions in function literal syntax, i.e.,` (x: Int) => x + 1`, and those functions can be represented by objects, which are called function values.
12
+
* Scala supports first-class functions, which means you can express functions in function literal syntax, i.e.` (x: Int) => x + 1`, and those functions can be represented by objects, which are called function values.
Copy file name to clipboardExpand all lines: src/main/scala/stdlib/Implicits.scala
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ object Implicits extends FlatSpec with Matchers with org.scalaexercises.definiti
10
10
11
11
/** The actual arguments that are eligible to be passed to an implicit parameter fall into two categories:
12
12
*
13
-
* - First, eligible are all identifiers x that can be accessed at the point of the method call without a prefix and that denote an implicit definition or an implicit parameter.
14
-
* - Second, eligible are also all members of companion modules of the implicit parameter's type that are labeled implicit.
13
+
* - First, eligible are all identifiers x that can be accessed at the point of the method call without a prefix and that denote an implicit definition or an implicit parameter.
14
+
* - Second, eligible are also all members of companion modules of the implicit parameter's type that are labeled implicit.
15
15
*
16
16
* In the following example we define a method `sum` which computes the sum of a list of elements using the monoid's `add` and `unit` operations. Please note that implicit values can not be top-level, they have to be members of a template.
17
17
*
@@ -46,7 +46,7 @@ object Implicits extends FlatSpec with Matchers with org.scalaexercises.definiti
46
46
* abc
47
47
* }}}
48
48
*
49
-
* Implicits wrap around existing classes to provide extra functionality. This is similar to *monkey patching* in **Ruby**, and *Meta-Programming* in **Groovy**.
49
+
* Implicits wrap around existing classes to provide extra functionality. This is similar to monkey patching in Ruby and meta-programming in Groovy.
50
50
*
51
51
* Creating a method `isOdd` for `Int`, which doesn't exist:
0 commit comments