Skip to content

zh-cn for Scala Tour:extractor-objects.md #1183

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 3 commits into from
Dec 4, 2018

Conversation

realwunan
Copy link
Contributor

Simplified Chinese version of Scala Tour: Extractor Objects

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it seems the periods are not translated :)


这里 `apply` 方法用 `name` 创建一个 `CustomerID` 字符串. 而 `unapply` 方法正好相反, 它返回 `name` . 当我们调用 `CustomerID("Sukyoung")` , 其实是调用了 `CustomerID.apply("Sukyoung")` 的简化语法. 当我们调用 `case CustomerID(name) => println(name)`, 就是在调用提取器方法.

因为在定义一个值的时候可以使用一个模式来引入一个新的变量, 提取器可以用来初始化这个变量, 使用 unapply 方法来生成值.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量定义可以使用模式引入变量?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's much better, thanks a lot.


* 如果只是用来测试, 返回一个 `Boolean` 类型的值. 例如 `case even()`.
* 如果只是用来提取单个 T 类型的值, 返回 `Option[T]`.
* 如果你想要提取多个值, 类型分别为 `T1,...,Tn`, 把它们放在一个可选的元祖中 `Option[(T1,...,Tn)]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: 元祖 -> 元组

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果...可以...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot.


`unapply` 方法的返回值应当符合下面的某一条:

* 如果只是用来测试, 返回一个 `Boolean` 类型的值. 例如 `case even()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试 -> 判断真假?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

语义通顺了很多

@realwunan
Copy link
Contributor Author

Just change the translation to use Chinese punctuation.

@liufengyun
Copy link
Contributor

LGTM, thanks a lot for the contribution @realwunan 🎉

@liufengyun liufengyun merged commit 8bc754f into scala:master Dec 4, 2018
@realwunan realwunan deleted the extractor-objects branch December 4, 2018 12:43
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.

3 participants