Skip to content

Link Tour of scala to Scala book #1671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2020
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
2 changes: 1 addition & 1 deletion _tour/abstract-type-members.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: tour
title: Abstract Type Members
partof: scala-tour
num: 23
num: 25
next-page: compound-types
previous-page: inner-classes
topics: abstract type members
Expand Down
4 changes: 2 additions & 2 deletions _tour/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ layout: tour
title: Annotations
partof: scala-tour

num: 32
next-page: default-parameter-values
num: 34
next-page: packages-and-imports
previous-page: by-name-parameters

redirect_from: "/tutorials/tour/annotations.html"
Expand Down
4 changes: 4 additions & 0 deletions _tour/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,7 @@ object Main {
println("Hello, Scala developer!")
}
```

## More resources

* [Scala book](/overviews/scala-book/prelude-taste-of-scala.html) overview
2 changes: 1 addition & 1 deletion _tour/by-name-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: By-name Parameters
partof: scala-tour

num: 31
num: 33
next-page: annotations
previous-page: operators

Expand Down
6 changes: 5 additions & 1 deletion _tour/case-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Case Classes
partof: scala-tour

num: 11
num: 13
next-page: pattern-matching
previous-page: multiple-parameter-lists
prerequisite-knowledge: classes, basics, mutability
Expand Down Expand Up @@ -54,3 +54,7 @@ message5.recipient // claire@bourgogne.fr
message5.body // "Me zo o komz gant ma amezeg"
```
The recipient of `message4` is used as the sender of `message5` but the `body` of `message4` was copied directly.

## More resources

* Learn more about case classes in the [Scala Book](/overviews/scala-book/case-classes.html)
7 changes: 6 additions & 1 deletion _tour/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Classes
partof: scala-tour

num: 4
next-page: traits
next-page: default-parameter-values
previous-page: unified-types
topics: classes
prerequisite-knowledge: no-return-keyword, type-declaration-syntax, string-interpolation, procedures
Expand Down Expand Up @@ -108,3 +108,8 @@ class Point(x: Int, y: Int)
val point = new Point(1, 2)
point.x // <-- does not compile
```

## More resources

* Learn more about Classes in the [Scala Book](/overviews/scala-book/classes.html)
* How to use [Auxiliary Class Constructors](/overviews/scala-book/classes-aux-constructors.html)
2 changes: 1 addition & 1 deletion _tour/compound-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Compound Types
partof: scala-tour

num: 24
num: 26
next-page: self-types
previous-page: abstract-type-members

Expand Down
4 changes: 2 additions & 2 deletions _tour/default-parameter-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ layout: tour
title: Default Parameter Values
partof: scala-tour

num: 33
num: 6
next-page: named-arguments
previous-page: annotations
previous-page: classes
prerequisite-knowledge: named-arguments, function syntax

redirect_from: "/tutorials/tour/default-parameter-values.html"
Expand Down
2 changes: 1 addition & 1 deletion _tour/extractor-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Extractor Objects
partof: scala-tour

num: 16
num: 18
next-page: for-comprehensions
previous-page: regular-expression-patterns

Expand Down
6 changes: 5 additions & 1 deletion _tour/for-comprehensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: For Comprehensions
partof: scala-tour

num: 17
num: 19
next-page: generic-classes
previous-page: extractor-objects

Expand Down Expand Up @@ -62,3 +62,7 @@ def foo(n: Int, v: Int) =

foo(10, 10)
```

## More resources

* Other examples of "For comprehension" in the [Scala Book](/overviews/scala-book/for-expressions.html)
2 changes: 1 addition & 1 deletion _tour/generic-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Generic Classes
partof: scala-tour

num: 18
num: 20
next-page: variances
previous-page: for-comprehensions
assumed-knowledge: classes unified-types
Expand Down
4 changes: 2 additions & 2 deletions _tour/higher-order-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Higher-order Functions
partof: scala-tour

num: 8
num: 10
next-page: nested-functions
previous-page: mixin-class-composition

Expand Down Expand Up @@ -35,7 +35,7 @@ val salaries = Seq(20000, 70000, 40000)
val newSalaries = salaries.map(x => x * 2) // List(40000, 140000, 80000)
```
Notice how `x` is not declared as an Int in the above example. That's because the
compiler can infer the type based on the type of function map expects. An even more idiomatic way to write the same piece of code would be:
compiler can infer the type based on the type of function map expects (see [Currying](/tour/multiple-parameter-lists.html). An even more idiomatic way to write the same piece of code would be:

```tut
val salaries = Seq(20000, 70000, 40000)
Expand Down
2 changes: 1 addition & 1 deletion _tour/implicit-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Implicit Conversions
partof: scala-tour

num: 27
num: 29
next-page: polymorphic-methods
previous-page: implicit-parameters

Expand Down
2 changes: 1 addition & 1 deletion _tour/implicit-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Implicit Parameters
partof: scala-tour

num: 26
num: 28
next-page: implicit-conversions
previous-page: self-types

Expand Down
2 changes: 1 addition & 1 deletion _tour/inner-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Inner Classes
partof: scala-tour

num: 22
num: 24
next-page: abstract-type-members
previous-page: lower-type-bounds

Expand Down
2 changes: 1 addition & 1 deletion _tour/lower-type-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Lower Type Bounds
partof: scala-tour

num: 21
num: 23
next-page: inner-classes
previous-page: upper-type-bounds
prerequisite-knowledge: upper-type-bounds, generics, variance
Expand Down
2 changes: 1 addition & 1 deletion _tour/mixin-class-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Class Composition with Mixins
partof: scala-tour

num: 7
num: 9
next-page: higher-order-functions
previous-page: tuples
prerequisite-knowledge: inheritance, traits, abstract-classes, unified-types
Expand Down
2 changes: 1 addition & 1 deletion _tour/multiple-parameter-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Multiple Parameter Lists (Currying)
partof: scala-tour

num: 10
num: 12
next-page: case-classes
previous-page: nested-functions

Expand Down
4 changes: 2 additions & 2 deletions _tour/named-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ layout: tour
title: Named Arguments
partof: scala-tour

num: 34
next-page: packages-and-imports
num: 5
next-page: traits
previous-page: default-parameter-values
prerequisite-knowledge: function-syntax

Expand Down
2 changes: 1 addition & 1 deletion _tour/nested-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Nested Methods
partof: scala-tour

num: 9
num: 11
next-page: multiple-parameter-lists
previous-page: higher-order-functions

Expand Down
2 changes: 1 addition & 1 deletion _tour/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Operators
partof: scala-tour

num: 30
num: 32
next-page: by-name-parameters
previous-page: type-inference
prerequisite-knowledge: case-classes
Expand Down
2 changes: 1 addition & 1 deletion _tour/packages-and-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: Packages and Imports
partof: scala-tour

num: 35
previous-page: named-arguments
next-page: package-objects
previous-page: annotations
---

# Packages and Imports
Expand Down
7 changes: 5 additions & 2 deletions _tour/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ layout: tour
title: Pattern Matching
partof: scala-tour

num: 12

num: 14
next-page: singleton-objects
previous-page: case-classes
prerequisite-knowledge: case-classes, string-interpolation, subtyping
Expand Down Expand Up @@ -147,3 +146,7 @@ This is useful for pattern matching because we don't need a "catch all" case.

Scala's pattern matching statement is most useful for matching on algebraic types expressed via [case classes](case-classes.html).
Scala also allows the definition of patterns independently of case classes, using `unapply` methods in [extractor objects](extractor-objects.html).

## More resources

* More details on match expressions in the [Scala Book](/overviews/scala-book/match-expressions.html)
2 changes: 1 addition & 1 deletion _tour/polymorphic-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Polymorphic Methods
partof: scala-tour

num: 28
num: 30

next-page: type-inference
previous-page: implicit-conversions
Expand Down
2 changes: 1 addition & 1 deletion _tour/regular-expression-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Regular Expression Patterns
partof: scala-tour

num: 15
num: 17

next-page: extractor-objects
previous-page: singleton-objects
Expand Down
2 changes: 1 addition & 1 deletion _tour/self-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Self-type
partof: scala-tour

num: 25
num: 27
next-page: implicit-parameters
previous-page: compound-types
topics: self-types
Expand Down
7 changes: 5 additions & 2 deletions _tour/singleton-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ layout: tour
title: Singleton Objects
partof: scala-tour

num: 13

num: 15
next-page: regular-expression-patterns
previous-page: pattern-matching
redirect_from: "/tutorials/tour/singleton-objects.html"
Expand Down Expand Up @@ -105,3 +104,7 @@ Note: If a class or object has a companion, both must be defined in the same fil
`static` members in Java are modeled as ordinary members of a companion object in Scala.

When using a companion object from Java code, the members will be defined in a companion class with a `static` modifier. This is called _static forwarding_. It occurs even if you haven't defined a companion class yourself.

## More resources

* Learn more about Companion objects in the [Scala Book](/overviews/scala-book/companion-objects.html)
10 changes: 8 additions & 2 deletions _tour/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ layout: tour
title: Traits
partof: scala-tour

num: 5
num: 7
next-page: tuples
previous-page: classes
previous-page: named-arguments
topics: traits
prerequisite-knowledge: expressions, classes, generics, objects, companion-objects

Expand Down Expand Up @@ -79,3 +79,9 @@ animals.append(cat)
animals.foreach(pet => println(pet.name)) // Prints Harry Sally
```
The `trait Pet` has an abstract field `name` that gets implemented by Cat and Dog in their constructors. On the last line, we call `pet.name`, which must be implemented in any subtype of the trait `Pet`.


## More resources

* Learn more about traits in the [Scala Book](/overviews/scala-book/traits-intro.html)
* Use traits to define [Enum](/overviews/scala-book/enumerations-pizza-class.html)
6 changes: 5 additions & 1 deletion _tour/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Tuples
partof: scala-tour

num: 6
num: 8
next-page: mixin-class-composition
previous-page: traits
topics: tuples
Expand Down Expand Up @@ -79,3 +79,7 @@ for ((a, b) <- numPairs) {

Users may sometimes find it hard to choose between tuples and case classes. Case classes have named elements. The names can improve the readability of some kinds of code. In the planet example above, we might define `case class Planet(name: String, distance: Double)` rather than using tuples.


## More resources

* Learn more about tuples in the [Scala Book](/overviews/scala-book/tuples.html)
2 changes: 1 addition & 1 deletion _tour/type-inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Type Inference
partof: scala-tour

num: 29
num: 31
next-page: operators
previous-page: polymorphic-methods
---
Expand Down
2 changes: 1 addition & 1 deletion _tour/upper-type-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Upper Type Bounds
partof: scala-tour
categories: tour
num: 20
num: 22
next-page: lower-type-bounds
previous-page: variances

Expand Down
2 changes: 1 addition & 1 deletion _tour/variances.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: tour
title: Variances
partof: scala-tour

num: 19
num: 21
next-page: upper-type-bounds
previous-page: generic-classes

Expand Down