diff --git a/Syntactic Conveniences/Functions/task.md b/Syntactic Conveniences/Functions/task.md index 5cc014d..03fb5c1 100644 --- a/Syntactic Conveniences/Functions/task.md +++ b/Syntactic Conveniences/Functions/task.md @@ -20,7 +20,7 @@ So functions are objects with `apply` methods. There are also traits `Function2`, `Function3`, ... for functions which take more parameters (currently up to 22). -## Expansion of Function Values +### Expansion of Function Values An anonymous function such as @@ -39,7 +39,7 @@ or, shorter, using *anonymous class syntax*: def apply(x: Int) = x * x } -## Expansion of Function Calls +### Expansion of Function Calls A function call, such as `f(a, b)`, where `f` is a value of some class type, is expanded to: @@ -58,7 +58,7 @@ would be: } f.apply(7) -## Functions and Methods +### Functions and Methods Note that a method such as @@ -71,7 +71,7 @@ converted automatically to the function value (x: Int) => f(x) -## `for` expressions +### `for` expressions You probably noticed that several data types of the standard library have methods named `map`, `flatMap` and `filter`. @@ -79,7 +79,7 @@ have methods named `map`, `flatMap` and `filter`. These methods are so common in practice that Scala supports a dedicated syntax: *for expressions*. -## `map` +### `map` Thus, instead of writing the following: @@ -91,7 +91,7 @@ You can write: You can read it as “for every value, that I name ‘x’, in ‘xs’, return ‘x + 1’”. -## `filter` +### `filter` Also, instead of writing the following: @@ -109,7 +109,7 @@ with the previous one: // Equivalent to the following: xs.filter(x => x % 2 == 0).map(x => x + 1) -## `flatMap` +### `flatMap` Finally, instead of writing the following: diff --git a/Syntactic Conveniences/Methods Parameters/task.md b/Syntactic Conveniences/Methods Parameters/task.md index 0035123..600d8fa 100644 --- a/Syntactic Conveniences/Methods Parameters/task.md +++ b/Syntactic Conveniences/Methods Parameters/task.md @@ -36,10 +36,10 @@ will supply it for us, by using its default value. ### Repeated Parameters You can define a function that can receive an arbitrary number of -parameters (of the same type) as follows. +parameters (of the same type). -The `average` function takes at least one `Int` parameter and then +The `average` function defined in the code editor takes at least one `Int` parameter and then an arbitrary number of other values and computes their average. By forcing users to supply at least one parameter, we make it impossible for them to compute the average of an empty list of numbers. @@ -57,6 +57,6 @@ you can give meaningful names to *type expressions*. ## Exercise -- Complete the step default parameter in the `Range` definition for it to be equal to 1. -- Complete the `average` definition for it to take a various range of numbers. -- Complete the `Result` definition for its Right to be a tuple of integer numbers. \ No newline at end of file +- Complete the `step` default parameter in the `Range` definition for it to be equal to 1. +- Complete the `average` definition for it to take an arbitrary number of parameters. +- Complete the `Result` definition for its `Right` to be a tuple of integer numbers. \ No newline at end of file diff --git a/Syntactic Conveniences/String Interpolation/task.md b/Syntactic Conveniences/String Interpolation/task.md index d7f3e9b..cbc4f72 100644 --- a/Syntactic Conveniences/String Interpolation/task.md +++ b/Syntactic Conveniences/String Interpolation/task.md @@ -16,4 +16,4 @@ surround it with braces. ## Exercise -Complete the `greetLouder` method to say Hello, Scala in the upper case. +Complete the `greetLouder` method to say "Hello, Scala" in the upper case. diff --git a/Syntactic Conveniences/Tuples/task.md b/Syntactic Conveniences/Tuples/task.md index 7c7576b..34da710 100644 --- a/Syntactic Conveniences/Tuples/task.md +++ b/Syntactic Conveniences/Tuples/task.md @@ -7,18 +7,18 @@ a complete case class for it. In such a case you can use *tuples*: -In the above example, the type `(Int, String)` represents a pair whose +In the example in the code editor, the type `(Int, String)` represents a pair whose first element is an `Int` and whose second element is a `String`. Similarly, the value `(i, s)` is a pair whose first element is `i` and whose second element is `s`. More generally, a type `(T1, …, Tn)` is a *tuple type* of n elements -whose i^th^ element has type `Ti`. +whose i'th element has type `Ti`. And a value `(t1, … tn)` is a *tuple value* of n elements. -## Manipulating Tuples +### Manipulating Tuples You can retrieve the elements of a tuple by using a *tuple pattern*.