From fc8afd5d55d56dd4d1d595a959fbb2d5a7749190 Mon Sep 17 00:00:00 2001 From: sofiiako <19rubisco93@gmail.com> Date: Thu, 1 Jul 2021 15:05:46 +0300 Subject: [PATCH 1/5] Updated String Interpolation --- Syntactic Conveniences/String Interpolation/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Syntactic Conveniences/String Interpolation/task.md b/Syntactic Conveniences/String Interpolation/task.md index d7f3e9b..742a021 100644 --- a/Syntactic Conveniences/String Interpolation/task.md +++ b/Syntactic Conveniences/String Interpolation/task.md @@ -14,6 +14,6 @@ dynamic values in it with `$`. If you want to splice a complex expression (more than just an identifier), surround it with braces. -## Exercise +### 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. From 31257de6b7fe8b2cc4d12c735200660c3938ba33 Mon Sep 17 00:00:00 2001 From: sofiiako <19rubisco93@gmail.com> Date: Thu, 1 Jul 2021 15:23:21 +0300 Subject: [PATCH 2/5] Updated Tuples --- Syntactic Conveniences/Tuples/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Syntactic Conveniences/Tuples/task.md b/Syntactic Conveniences/Tuples/task.md index 7c7576b..1d15089 100644 --- a/Syntactic Conveniences/Tuples/task.md +++ b/Syntactic Conveniences/Tuples/task.md @@ -7,24 +7,24 @@ 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*. Alternatively, you can retrieve the 1st element with the `_1` member, the 2nd element with the `_2` member, etc. -## Exercise +### Exercise Complete the `pair` method definition to return the tuple including the parameters passed. From e5ba591d065dd75d2d3dd8edb7e226affe29b2cd Mon Sep 17 00:00:00 2001 From: sofiiako <19rubisco93@gmail.com> Date: Thu, 1 Jul 2021 15:30:55 +0300 Subject: [PATCH 3/5] Fixed subheadings in Functions as Objects --- Syntactic Conveniences/Functions/task.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Syntactic Conveniences/Functions/task.md b/Syntactic Conveniences/Functions/task.md index 5cc014d..47d9c74 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: @@ -122,7 +122,7 @@ You can write: You can read it as “for every value ‘x’ in ‘xs’, and then for every value ‘y’ in ‘ys’, return ‘(x, y)’”. -## Exercise +### Exercise Complete the function, so it becomes an equivalent of the following de-sugared code: From 23d62d25e26cae685fb801021c5e05c30a84e996 Mon Sep 17 00:00:00 2001 From: sofiiako <19rubisco93@gmail.com> Date: Thu, 1 Jul 2021 15:50:25 +0300 Subject: [PATCH 4/5] Updated Named Parameters --- Syntactic Conveniences/Methods Parameters/task.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Syntactic Conveniences/Methods Parameters/task.md b/Syntactic Conveniences/Methods Parameters/task.md index 0035123..875ec95 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. @@ -56,7 +56,7 @@ In the same way as you can give meaningful names to expressions, 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 +### 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 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 From fee1881dcb4068fc5810fcf7f0eb609b873fffea Mon Sep 17 00:00:00 2001 From: sofiiako <19rubisco93@gmail.com> Date: Thu, 1 Jul 2021 17:30:05 +0300 Subject: [PATCH 5/5] Fixed subheadings (Exercise) --- Syntactic Conveniences/Functions/task.md | 2 +- Syntactic Conveniences/Methods Parameters/task.md | 2 +- Syntactic Conveniences/String Interpolation/task.md | 2 +- Syntactic Conveniences/Tuples/task.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Syntactic Conveniences/Functions/task.md b/Syntactic Conveniences/Functions/task.md index 47d9c74..03fb5c1 100644 --- a/Syntactic Conveniences/Functions/task.md +++ b/Syntactic Conveniences/Functions/task.md @@ -122,7 +122,7 @@ You can write: You can read it as “for every value ‘x’ in ‘xs’, and then for every value ‘y’ in ‘ys’, return ‘(x, y)’”. -### Exercise +## Exercise Complete the function, so it becomes an equivalent of the following de-sugared code: diff --git a/Syntactic Conveniences/Methods Parameters/task.md b/Syntactic Conveniences/Methods Parameters/task.md index 875ec95..600d8fa 100644 --- a/Syntactic Conveniences/Methods Parameters/task.md +++ b/Syntactic Conveniences/Methods Parameters/task.md @@ -56,7 +56,7 @@ In the same way as you can give meaningful names to expressions, you can give meaningful names to *type expressions*. -### Exercise +## 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 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 742a021..cbc4f72 100644 --- a/Syntactic Conveniences/String Interpolation/task.md +++ b/Syntactic Conveniences/String Interpolation/task.md @@ -14,6 +14,6 @@ dynamic values in it with `$`. If you want to splice a complex expression (more than just an identifier), surround it with braces. -### Exercise +## Exercise 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 1d15089..34da710 100644 --- a/Syntactic Conveniences/Tuples/task.md +++ b/Syntactic Conveniences/Tuples/task.md @@ -25,6 +25,6 @@ You can retrieve the elements of a tuple by using a *tuple pattern*. Alternatively, you can retrieve the 1st element with the `_1` member, the 2nd element with the `_2` member, etc. -### Exercise +## Exercise Complete the `pair` method definition to return the tuple including the parameters passed.