Skip to content

Commit ab7b69b

Browse files
authored
Merge pull request #69 from rzats/text-tweaks
Text tweaks covering most of the tutorial
2 parents 8cba804 + 518b0c7 commit ab7b69b

34 files changed

+209
-212
lines changed

src/main/scala/stdlib/Asserts.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ object Asserts extends FlatSpec with Matchers with org.scalaexercises.definition
3636
* result shouldBe 3 // cannot customize equality, so fastest to compile, no parentheses required
3737
* }}}
3838
*
39-
* Come on, your turn: true and false values can be compared with should matchers
39+
* Come on, your turn: true and false values can be compared with should matchers:
4040
*/
4141
def scalaTestAsserts(res0: Boolean) {
4242
true should be(res0)
4343
}
4444

45-
/** Booleans in asserts can test equality.
45+
/** Booleans in asserts can test equality:
4646
*/
4747
def booleanAsserts(res0: Int) {
4848
val v1 = 4
@@ -51,7 +51,7 @@ object Asserts extends FlatSpec with Matchers with org.scalaexercises.definition
5151
/** `shouldEqual` is an assertion. It is from ScalaTest, not from the Scala language. */
5252
}
5353

54-
/** Sometimes we expect you to fill in the values
54+
/** Sometimes we expect you to fill in the values:
5555
*/
5656
def valuesAsserts(res0: Int) {
5757
assert(res0 == 1 + 1)

src/main/scala/stdlib/ByNameParameter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.scalatest._
66
*/
77
object ByNameParameter extends FlatSpec with Matchers with org.scalaexercises.definitions.Section {
88

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.
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:
1010
*/
1111
def takesUnitByNameParameter(res0: Either[Throwable, Int]) {
1212
def calc(x: () Int): Either[Throwable, Int] = {
@@ -24,7 +24,7 @@ object ByNameParameter extends FlatSpec with Matchers with org.scalaexercises.de
2424
y should be(res0)
2525
}
2626

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:
2828
*/
2929
def byNameParameter(res0: Either[Throwable, Int]) {
3030
def calc(x: Int): Either[Throwable, Int] = {
@@ -46,7 +46,7 @@ object ByNameParameter extends FlatSpec with Matchers with org.scalaexercises.de
4646
y should be(res0)
4747
}
4848

49-
/** By name parameters can also be used with an *Object* and apply to make interesting block-like calls
49+
/** By name parameters can also be used with `object` and `apply` to make interesting block-like calls:
5050
*/
5151
def withApplyByNameParameter(res0: String) {
5252
object PigLatinizer {

src/main/scala/stdlib/CaseClasses.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
88

99
/** 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.
1010
*
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`:
1212
*
1313
* {{{
1414
* abstract class Term
@@ -32,7 +32,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
3232
* println(x.name)
3333
* }}}
3434
*
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,
3636
*
3737
* {{{
3838
* val x1 = Var("x")
@@ -218,7 +218,7 @@ object CaseClasses extends FlatSpec with Matchers with org.scalaexercises.defini
218218
parts._4 should be(res3)
219219
}
220220

221-
/** Case classes are Serializable
221+
/** Case classes are `Serializable`:
222222
*/
223223
def serializableCaseClasses(res0: Boolean, res1: Boolean) {
224224
case class PersonCC(firstName: String, lastName: String)

src/main/scala/stdlib/Classes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Classes extends FlatSpec with Matchers with org.scalaexercises.definition
1414
* override def toString(): String = "(" + x + ", " + y + ")"
1515
* }
1616
* }}}
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`.
1818
*
1919
* 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`.
2020
*
@@ -31,7 +31,7 @@ object Classes extends FlatSpec with Matchers with org.scalaexercises.definition
3131
*
3232
* 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`.
3333
*
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:
3535
*
3636
*/
3737
def classWithValParameterClasses(res0: String) {

src/main/scala/stdlib/EmptyValues.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object EmptyValues extends FlatSpec with Matchers with org.scalaexercises.defini
1717
*
1818
* ==Nothing==
1919
*
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).
2121
*
2222
* ==Unit==
2323
*
@@ -47,41 +47,41 @@ object EmptyValues extends FlatSpec with Matchers with org.scalaexercises.defini
4747
None eq None shouldBe res0
4848
}
4949

50-
/** `None` can be converted to a *String*:
50+
/** `None` can be converted to a String:
5151
*/
5252
def noneToStringEmptyValues(res0: String) {
5353
assert(None.toString === res0)
5454
}
5555

56-
/** `None` can be converted to an empty list
56+
/** `None` can be converted to an empty list:
5757
*/
5858
def noneToListEmptyValues(res0: Boolean) {
5959
None.toList === Nil shouldBe res0
6060
}
6161

62-
/** `None` is considered empty
62+
/** `None` is considered empty:
6363
*/
6464
def noneAsEmptyEmptyValues(res0: Boolean) {
6565
assert(None.isEmpty === res0)
6666
}
6767

68-
/** `None` can be cast `Any`, `AnyRef` or `AnyVal`
68+
/** `None` can be cast to `Any`, `AnyRef` or `AnyVal`:
6969
*/
7070
def noneToAnyEmptyValues(res0: Boolean, res1: Boolean, res2: Boolean) {
7171
None.asInstanceOf[Any] === None shouldBe res0
7272
None.asInstanceOf[AnyRef] === None shouldBe res1
7373
None.asInstanceOf[AnyVal] === None shouldBe res2
7474
}
7575

76-
/** `None` can be used with `Option` instead of null references
76+
/** `None` can be used with `Option` instead of null references:
7777
*/
7878
def noneWithOptionEmptyValues(res0: Boolean, res1: Option[String]) {
7979
val optional: Option[String] = None
8080
assert(optional.isEmpty === res0)
8181
assert(optional === res1)
8282
}
8383

84-
/** `Some` is the opposite of `None` for `Option` types
84+
/** `Some` is the opposite of `None` for `Option` types:
8585
*/
8686
def someAgainstNoneEmptyValues(res0: Boolean, res1: Boolean) {
8787
val optional: Option[String] = Some("Some Value")

src/main/scala/stdlib/Extractors.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
2525
*
2626
* There are two syntactic conventions at work here:
2727
*
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)`.
3030
*
3131
* The code in the preceding example would be expanded as follows:
3232
*
@@ -38,9 +38,9 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
3838
* }}}
3939
* The return type of an `unapply` should be chosen as follows:
4040
*
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)]`.
4444
*
4545
* 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)`.
4646
*
@@ -76,7 +76,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
7676
d should be(res3)
7777
}
7878

79-
/** Of course an extractor can be used in pattern matching...
79+
/** An extractor can also be used in pattern matching:
8080
*/
8181
def patternMatchingExtractors(res0: String, res1: String) {
8282
class Car(val make: String, val model: String, val year: Short, val topSpeed: Short)
@@ -94,7 +94,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
9494
x._2 should be(res1)
9595
}
9696

97-
/** Since we aren't really using u and v in the previous pattern matching with can replace them with _.
97+
/** Since we aren't really using `u` and `v` in the previous pattern matching, they can be replaced with `_`:
9898
*/
9999
def withWildcardExtractors(res0: String, res1: String) {
100100
class Car(val make: String, val model: String, val year: Short, val topSpeed: Short)
@@ -132,7 +132,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
132132
result should be(res0)
133133
}
134134

135-
/** An extractor can be any stable object, including instantiated classes with an unapply method.
135+
/** An extractor can be any stable object, including instantiated classes with an unapply method:
136136
*/
137137
def anyObjectExtractors(res0: String) {
138138
class Car(val make: String, val model: String, val year: Short, val topSpeed: Short) {
@@ -149,7 +149,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
149149
result should be(res0)
150150
}
151151

152-
/** What is typical is to create a custom extractor in the companion object of the class. In this exercise, we use it as an assignment:
152+
/** A custom extractor is typically created in the companion object of the class. In this exercise, we use it as an assignment:
153153
*/
154154
def asAssignmentExtractors(res0: String, res1: Option[String], res2: String) {
155155
class Employee(
@@ -174,7 +174,7 @@ object Extractors extends FlatSpec with Matchers with org.scalaexercises.definit
174174
c should be(res2)
175175
}
176176

177-
/** In this exercise we use the unapply for pattern matching employee objects
177+
/** In this exercise we use `unapply` for pattern matching employee objects:
178178
*/
179179
def unapplyForPatternMatchingExtractors(res0: String) {
180180
class Employee(

src/main/scala/stdlib/ForExpressions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.scalatest._
77
*/
88
object ForExpressions extends FlatSpec with Matchers with org.scalaexercises.definitions.Section {
99

10-
/** For expressions can nest, with later generators varying more rapidly than earlier ones:
10+
/** `for` expressions can nest, with later generators varying more rapidly than earlier ones:
1111
*/
1212
def canBeNestedForExpressions(res0: Int, res1: Int) {
1313
val xValues = 1 to 4
@@ -19,7 +19,7 @@ object ForExpressions extends FlatSpec with Matchers with org.scalaexercises.def
1919
coordinates(4) should be(res0, res1)
2020
}
2121

22-
/** Using `for` we can make more readable code
22+
/** Using `for` we can make more readable code:
2323
*/
2424
def readableCodeForExpressions(res0: List[Int]) {
2525
val nums = List(List(1), List(2), List(3), List(4), List(5))

src/main/scala/stdlib/HigherOrderFunctions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
99

1010
/** 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.
1111
*
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.
1313
*/
1414
def meetLambdaHigherOrderFunctions(res0: Int, res1: Int, res2: Int, res3: Int, res4: Int, res5: Int) {
1515
def lambda = { x: Int x + 1 }
@@ -38,7 +38,7 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
3838
result5 should be(res5)
3939
}
4040

41-
/** An anonymous function can also take on a different look by taking out the brackets
41+
/** An anonymous function can also take on a different look by taking out the brackets:
4242
*/
4343
def differentLookHigherOrderFunctions(res0: Int) {
4444
def lambda = (x: Int) x + 1
@@ -70,7 +70,7 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
7070
result2 should be(res1)
7171
}
7272

73-
/** We can take that closure and throw it into a method and it will still hold the environment
73+
/** We can take that closure and throw it into a method and it will still hold the environment:
7474
*/
7575
def holdEnvironmentHigherOrderFunctions(res0: Int, res1: Int) {
7676
def summation(x: Int, y: Int Int) = y(x)
@@ -125,7 +125,7 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
125125

126126
/** Function taking another function as a parameter. Helps in composing functions.
127127
*
128-
* Hint: a map method applies the function to each element of a list
128+
* Hint: a map method applies the function to each element of a list.
129129
*/
130130
def functionAsParameterHigherOrderFunctions(res0: List[String], res1: List[String], res2: List[Int]) {
131131
def makeUpper(xs: List[String]) = xs map {

src/main/scala/stdlib/Implicits.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ object Implicits extends FlatSpec with Matchers with org.scalaexercises.definiti
1010

1111
/** The actual arguments that are eligible to be passed to an implicit parameter fall into two categories:
1212
*
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.
1515
*
1616
* 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.
1717
*
@@ -46,7 +46,7 @@ object Implicits extends FlatSpec with Matchers with org.scalaexercises.definiti
4646
* abc
4747
* }}}
4848
*
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.
5050
*
5151
* Creating a method `isOdd` for `Int`, which doesn't exist:
5252
*/

src/main/scala/stdlib/InfixPrefixandPostfixOperators.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import scala.language.postfixOps
88
*/
99
object InfixPrefixandPostfixOperators extends FlatSpec with Matchers with org.scalaexercises.definitions.Section {
1010

11-
/** Any method which takes a single parameter can be used as an infix operator: `a.m(b)` can be written `a m b`.
11+
/** Any method which takes a single parameter can be used as an infix operator: `a.m(b)` can also be written as `a m b`.
1212
*/
1313
def singleParameterInfixPrefixandPostfixOperators(res0: Int, res1: Int) {
1414
val g: Int = 3
1515
(g + 4) should be(res0) // + is an infix operator
1616
g.+(4) should be(res1) // same result but not using the infix operator
1717
}
1818

19-
/** Infix Operators do NOT work if an object has a method that takes two parameters:
19+
/** Infix operators do NOT work if an object has a method that takes two parameters:
2020
*/
2121
def notWithTwoInfixPrefixandPostfixOperators(res0: Int, res1: Int) {
2222
val g: String = "Check out the big brains on Brad!"
@@ -28,14 +28,14 @@ object InfixPrefixandPostfixOperators extends FlatSpec with Matchers with org.sc
2828
g.indexOf('o', 7) should be(res1) //indexOf(Char, Int) must use standard java/scala calls
2929
}
3030

31-
/** Any method which does not require a parameter can be used as a postfix operator: `a.m` can be written `a m`.
31+
/** Any method which does not require a parameter can be used as a postfix operator: `a.m` can be written as `a m`.
3232
*
33-
* For instance `a.##(b)` can be written `a ## b` and `a.!` can be written `a!`
33+
* For instance, `a.+(b)` is equivalent to `a + b` and `a.!` is the same as `a!`.
3434
*
35-
* **Postfix operators** have lower precedence than **infix operators**, so:
36-
* - `foo bar baz` means `foo.bar(baz)`.
37-
* - `foo bar baz bam` means `(foo.bar(baz)).bam`
38-
* - `foo bar baz bam bim` means `(foo.bar(baz)).bam(bim)`.
35+
* Postfix operators have lower precedence than infix operators, so:
36+
* - `foo bar baz` means `foo.bar(baz)`.
37+
* - `foo bar baz bam` means `(foo.bar(baz)).bam`
38+
* - `foo bar baz bam bim` means `(foo.bar(baz)).bam(bim)`.
3939
*/
4040
def postfixOperatorInfixPrefixandPostfixOperators(res0: String) {
4141
val g: Int = 31
@@ -50,7 +50,7 @@ object InfixPrefixandPostfixOperators extends FlatSpec with Matchers with org.sc
5050
(-g) should be(res0)
5151
}
5252

53-
/** Here we create our own prefix operator for our own class. The only identifiers that can be used as prefix operators are `+`, `-`, `!`, and `~`:
53+
/** Here's how to create a prefix operator for our own class. The only identifiers that can be used as prefix operators are `+`, `-`, `!`, and `~`:
5454
*/
5555
def ourOwnOperatorInfixPrefixandPostfixOperators(res0: String, res1: String) {
5656
class Stereo {

0 commit comments

Comments
 (0)