Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Syntactic Conveniences/Functions/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -58,7 +58,7 @@ would be:
}
f.apply(7)

## Functions and Methods
### Functions and Methods

Note that a method such as

Expand All @@ -71,15 +71,15 @@ 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`.

These methods are so common in practice that Scala supports a dedicated
syntax: *for expressions*.

## `map`
### `map`

Thus, instead of writing the following:

Expand All @@ -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:

Expand All @@ -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:

Expand Down
10 changes: 5 additions & 5 deletions Syntactic Conveniences/Methods Parameters/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
- 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.
2 changes: 1 addition & 1 deletion Syntactic Conveniences/String Interpolation/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions Syntactic Conveniences/Tuples/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*.

Expand Down