Skip to content

#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

Merged
merged 1 commit into from
Sep 21, 2018
Merged

#850:Tuples page added to tour #1144

merged 1 commit into from
Sep 21, 2018

Conversation

mghildiy
Copy link
Contributor

No description provided.

@jvican
Copy link
Member

jvican commented Sep 14, 2018

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?

@mghildiy
Copy link
Contributor Author

Ok.

Copy link
Contributor

@adriaanm adriaanm left a 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).
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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
---

_단일 상속_ 만을 지원하는 여러 언어와는 달리, 스칼라는 더욱 일반화된 시각에서 클래스를 재사용한다. 스칼라는 새로운 클래스를 정의할 때 _클래스의 새로운 멤버 정의_ (즉, 슈퍼클래스와 비교할 때 변경된 부분)를 재사용할 수 있다. 이를 _믹스인 클래스 컴포지션_ 이라고 부른다. 이터레이터를 추상화한 다음 예제를 살펴보자.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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_
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@adriaanm adriaanm Sep 21, 2018

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.
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member

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.
Copy link
Contributor

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].
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Member

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.

@SethTisue
Copy link
Member

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..."

@mghildiy
Copy link
Contributor Author

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.
Copy link
Contributor

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.

@SethTisue
Copy link
Member

@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.

@jvican
Copy link
Member

jvican commented Sep 17, 2018

Thanks I just restarted the CI

@mghildiy
Copy link
Contributor Author

Please merge it.

@adriaanm adriaanm merged commit babbc49 into scala:master Sep 21, 2018
@mghildiy mghildiy deleted the issue850 branch September 23, 2018 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants