-
Notifications
You must be signed in to change notification settings - Fork 1k
Translate tuples.md and Modify the 'num' of elements in tour docs #1403
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
Changes from 1 commit
c4d8b9d
8f671a0
dfc1f84
39f9c1b
04919e2
7bb7101
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 10 | ||
num: 11 | ||
language: ko | ||
|
||
next-page: pattern-matching | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 7 | ||
num: 8 | ||
language: ko | ||
|
||
next-page: nested-functions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 6 | ||
num: 7 | ||
language: ko | ||
|
||
next-page: higher-order-functions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 9 | ||
num: 10 | ||
language: ko | ||
|
||
next-page: case-classes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 8 | ||
num: 9 | ||
language: ko | ||
|
||
next-page: multiple-parameter-lists | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ discourse: false | |
|
||
partof: scala-tour | ||
|
||
num: 11 | ||
num: 12 | ||
language: ko | ||
|
||
next-page: singleton-objects | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,79 @@ title: Tuples | |
discourse: true | ||
|
||
partof: scala-tour | ||
num: | ||
|
||
num: 6 | ||
language: ko | ||
|
||
next-page: mixin-class-composition | ||
previous-page: traits | ||
topics: tuples | ||
|
||
redirect_from: "/tutorials/tour/tuples.html" | ||
--- | ||
|
||
(this section of the tour has not been translated yet. pull request | ||
with translation welcome!) | ||
스칼라에서 하나의 튜플은 정해진 갯수의 각각 구별된 타입을 갖는 엘리먼트들을 포함하는 하나의 값이다. 튜플은 불변적이다. | ||
|
||
튜플은 특히 메소드로부터 여러개의 값을 리턴하는데 편리하게 사용할 수 있다. | ||
|
||
두개의 엘리먼트를 갖는 튜플은 다음과 같이 생성할 수 있다: | ||
|
||
```tut | ||
val ingredient = ("Sugar" , 25) | ||
``` | ||
|
||
위 코드는 `String`과 `Int` 엘리먼트를 포함하는 튜플을 생성한다. | ||
|
||
`ingredient`의 추론된 타입은 `Tuple2[String, Int]`의 약칭인 `(String, Int)`이다. | ||
|
||
튜플들을 나타내기 위해서 Scala에서는 다음과 같은 형태의 클래스들을 사용한다: `Tuple2`, `Tuple3`, ... ,`Tuple22`. | ||
각 클래스는 파라미터 타입의 갯수 만큼 엘리먼트들을 가지고 있다. | ||
|
||
## 엘리먼트 접근하기 | ||
|
||
튜플의 엘리먼트에 접근하기 위한 한가지 방법은 위치로 접근하는 것이다. 각 개별적인 엘리먼트들은 `_1`, `_2`, ... 이와 같은 방법으로 이름지어진다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When translating into Korean, it seems natural to use active type rather than passive type. 각 개별적인 엘리먼트들은 How about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 각 and 개별 is duplicate semantically. 각 개별적인 엘리먼트들은 How about this? 각 요소들은 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @horace-velmont @byeonggukgong Both are good suggestions! |
||
|
||
```tut | ||
println(ingredient._1) // Sugar | ||
println(ingredient._2) // 25 | ||
``` | ||
|
||
## 튜플에서의 패턴 매칭 | ||
|
||
하나의 튜플은 패턴 매칭을 사용하여 분리할 수 있다: | ||
|
||
```tut | ||
val (name, quantity) = ingredient | ||
println(name) // Sugar | ||
println(quantity) // 25 | ||
``` | ||
|
||
여기에서 `name`의 추론된 타입은 `String`이고 `quantity`의 추론된 타입은 `Int`이다. | ||
|
||
여기 튜플을 패턴 매칭한 또 다른 예제가 있다: | ||
|
||
```tut | ||
val planets = | ||
List(("Mercury", 57.9), ("Venus", 108.2), ("Earth", 149.6), | ||
("Mars", 227.9), ("Jupiter", 778.3)) | ||
planets.foreach{ | ||
case ("Earth", distance) => | ||
println(s"Our planet is $distance million kilometers from the sun") | ||
case _ => | ||
} | ||
``` | ||
|
||
또는 `for` comprehension에서: | ||
|
||
```tut | ||
val numPairs = List((2, 5), (3, -7), (20, 56)) | ||
for ((a, b) <- numPairs) { | ||
println(a * b) | ||
} | ||
``` | ||
|
||
## 튜플과 케이스 클래스 | ||
|
||
사용자들은 때때로 튜플과 케이스 클래스 사이의 선택의 기로에서 무엇을 선택해야할지 힘들어 할지도 모른다. 케이스 클래스는 이름이 있는 엘리먼트들을 갖는다. 그 엘리먼트의 이름들은 어떤 종류의 코드에서 가독성을 향상 시켜줄 수 있다. 위의 planet 예제에서 우리는 튜플을 사용하는 것보다 `case class Planet(name: String, distance: Double)`로 정의 하는 것이 더 나을 수도 있다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그 엘리먼트의 이름들은 어떤 종류의 코드에서 가독성을 향상 시켜줄 수 있다. I suggest, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The target of these documents is the Scala beginner. So I don't think you need to use "사용자, 유저 등" explicitly. 사용자들은 때때로 튜플과 케이스 클래스 사이의 선택의 기로에서 무엇을 선택해야할지 힘들어 할지도 모른다. How about this? 때로는 튜플과 케이스 클래스 중 무엇을 사용할지 고르는데 힘들 수 있다. |
||
|
||
이한샘 옮김 |
Uh oh!
There was an error while loading. Please reload this 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.
It's a good idea to translate people so that you can understand them better. And I translate as much as possible into Korean. I prefer a way to increase readability in parentheses if necessary.
스칼라에서 하나의 튜플은 정해진 갯수의 각각 구별된 타입을 갖는 엘리먼트들을 포함하는 하나의 값이다.
How about this?
스칼라에서 튜플은 정해진 요소(element)를 가지는 값으로 각 요소는 고유한 타입을 가진다.