-
Notifications
You must be signed in to change notification settings - Fork 1k
#850:Tuples page added to tour #1144
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
Conversation
I'd like to review this soon, but it looks like I'm all busy until the end of next week. @mghildiy Could you post to Scala Contributors asking for reviewers for this PR? |
Ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I left a few suggestions.
_tour/tuples.md
Outdated
## Accessing the elements | ||
|
||
Tuple elements are accessed using underscore syntax. | ||
tuple._n gives nth element(given there are that many elements). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote as: tuple._n
_tour/tuples.md
Outdated
println(ingredient._2) // 25 | ||
``` | ||
|
||
## Iterating a tuple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before you get to productIterator
, which I think is a bit of a corner case, I'd show destructuring using patterns. Right now, you have shown how to do this in local vals, but the same applies to pattern matching (x match { case (a,b) => ...
), function literals ({ case (a, b) => a + b }
), and for comprehensions (for ( (a, b) <- pairs ) ...
).
_tour/tuples.md
Outdated
ingredient.toString // (Sugar,25) | ||
``` | ||
|
||
Scala tuple also supports destructuring. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump this to a ##
header.
PS: I think it's kind of neat to mention that ()
is conceptually Tuple0
, or Unit
. There can only be one value of this type since it has no elements.
Maybe one final comment: you should use case classes whenever the elements have more meaning.
@@ -10,7 +10,7 @@ num: 6 | |||
language: ko | |||
|
|||
next-page: higher-order-functions | |||
previous-page: traits | |||
previous-page: tuples | |||
--- | |||
|
|||
_단일 상속_ 만을 지원하는 여러 언어와는 달리, 스칼라는 더욱 일반화된 시각에서 클래스를 재사용한다. 스칼라는 새로운 클래스를 정의할 때 _클래스의 새로운 멤버 정의_ (즉, 슈퍼클래스와 비교할 때 변경된 부분)를 재사용할 수 있다. 이를 _믹스인 클래스 컴포지션_ 이라고 부른다. 이터레이터를 추상화한 다음 예제를 살펴보자. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced by the stub to indicate it hasn't been translated yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some translation there, not sure though if it corresponds to English version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, I got confused by the fact that this page is actually about mixins, and it's just the "previous" pointer that's being updated.
@@ -8,7 +8,7 @@ partof: scala-tour | |||
|
|||
num: 5 | |||
next-page: higher-order-functions | |||
previous-page: traits | |||
previous-page: tuples | |||
language: pt-br | |||
--- | |||
_Nota de tradução: A palavra `mixin` pode ser traduzida como mescla, porém é preferível utilizar a notação original_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced by the stub to indicate it hasn't been translated yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an explanation, but it does not correspond to the English version of the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I got confused by the fact that this page is actually about mixins, and it's just the "previous" pointer that's being updated.
_tour/tuples.md
Outdated
In Scala, a tuple is a class that can hold elements of different types. | ||
Tuples are immutable. | ||
|
||
Tuples come handy when we have to return multiple values from a function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
come in handy
_tour/tuples.md
Outdated
```tut | ||
val ingredient = ("Sugar" , 25) | ||
|
||
println(ingredient.getClass) // class scala.Tuple2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should expose beginners to .getClass
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, the better way to demonstrate that something conforms to a certain type is to show that it still compiles if you add a type ascription such as (String, Int)
or Tuple2[String, Int]
_tour/tuples.md
Outdated
|
||
Tuple in Scala is a series of classes: Tuple2, Tuple3, etc., through Tuple22. | ||
So when we create a tuple with n elements(n lying between 2 and 22), Scala basically instantiates | ||
one of the corresponding class from the group, parametrized with types of constituent elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class -> classes
parametrized -> parameterized
_tour/tuples.md
Outdated
Tuple in Scala is a series of classes: Tuple2, Tuple3, etc., through Tuple22. | ||
So when we create a tuple with n elements(n lying between 2 and 22), Scala basically instantiates | ||
one of the corresponding class from the group, parametrized with types of constituent elements. | ||
For eg., ingredient is of type Tuple2[String, int]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int -> Int
And I think it's better to show the (String, Int)
syntax to beginners and then explain that it is syntactic sugar for Tuple2[String, Int]
.
_tour/tuples.md
Outdated
Scala tuple also supports destructuring. | ||
|
||
```tut | ||
val(name, quantity) = ingredient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer a space between val
and (
.
_tour/tuples.md
Outdated
|
||
## Iterating a tuple | ||
|
||
Tuple provides productIterator method to iterate it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest omitting any mention of productIterator
(and related methods such as productElement
) from the tour entirely. They are rarely used, since they don't provide any type-safety.
thanks for writing this, nice work! I don't expect this will need much more work in order to become mergeable. of the various changes suggested, I think the single most important one is Adriaan's "I'd show destructuring using patterns..." |
This can be merged now. |
_tour/tuples.md
Outdated
} | ||
``` | ||
|
||
() is conceptually same as Tuple0, or Unit. There can only be one value of this type since it has no elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a bit tighter phrasing. The value ()
of type Unit
is conceptually the same as the value ()
of type Tuple0
(or type sugared ()
) if it existed, which it doesn't.
@jvican what do you make of the CI failure? I don't have rights to hit "rebuild" in Drone to see if it's transient. |
Thanks I just restarted the CI |
Please merge it. |
No description provided.