-
Notifications
You must be signed in to change notification settings - Fork 1k
modify/correct _zh-cn/index.md #2394
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
Changes from 10 commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
f38f5ff
modify/correct _zh-cn/index.md
benluo 30add30
modify _zh-cn/scala3/new-in-scala3.md
benluo 1c937b8
add _zh-cn/scala3/guides/tasty-overview.md
benluo 3de24bc
Merge branch 'scala:main' into main
benluo 770e5a7
Change _zh-cn/scala3/guides/tasty-overview.md
benluo 3edca3b
add few chapters in _zh-cn/overviews/scala3-book
benluo adcf494
Merge branch 'scala:main' into main
benluo e732e9e
translated all tastes files. in scala3-book.
benluo f87d417
Merge branch 'scala:main' into main
benluo 74405c5
modified according to review.
benluo 4422ef0
Merge branch 'scala:main' into main
benluo 313fdff
correct translation according review.
benluo 300d5cd
Missed one translation. Finish all corrects.
benluo 13c00a6
Merge branch 'scala:main' into main
benluo 3f33fc4
add _zh-cn/overviews/scala3-book/first-look-at-types.md
benluo e10cf0d
add _zh-cn/overviews/scala3-book/control-structures.md
benluo 3573d19
add two files as below
benluo d8cbad3
add _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo 76f49ec
Merge branch 'scala:main' into main
benluo 799b1f2
add and modified as below
benluo 3dd2ec3
add all methods*
benluo 66a752e
Merge branch 'scala:main' into main
benluo 8390a95
add functions
benluo b48eb7c
add _zh-cn/overviews/scala3-book/packaging-imports.md
benluo 6504fbf
Merge branch 'scala:main' into main
benluo c11754c
add all collections
benluo f751a72
add all fp files
benluo 3098a0f
Merge branch 'scala:main' into main
benluo d811aba
add all types files
benluo b9c6ac0
add all types files
benluo d8ba669
Merge branch 'scala:main' into main
benluo a98a687
add all ca-* files
benluo aadcb0e
add concurrency.md
benluo b845934
Merge branch 'scala:main' into main
benluo bb47995
add all tools files
benluo 4bb25d3
Merge branch 'scala:main' into main
benluo c59f3ba
add interacting-with-java.md
benluo 76e08bf
add all scala-for-* files. Finish all files in Scala3-book.
benluo d3637fb
corrected broken link in concurrency.md
benluo 4f3b6da
Merge branch 'scala:main' into main
benluo 00e7ca6
Merge branch 'scala:main' into main
benluo 8fa8ac4
Merge branch 'scala:main' into main
benluo 585c7ac
Merge branch 'scala:main' into main
benluo 47aab08
correct ca.* files
benluo de48d7e
Merge branch 'scala:main' into main
benluo 00edb7d
Merge branch 'scala:main' into main
benluo ddcf921
modified translation according to review.
benluo 951c842
Merge branch 'scala:main' into main
benluo 7e54512
correct collections-classes.md
benluo 86fdf8b
change translation according to review on Jul 19
fca798c
Merge branch 'scala:main' into main
benluo 9cdf9fe
Merge branch 'scala:main' into main
benluo e387055
Merge branch 'scala:main' into main
benluo 6a507ea
modified according to review on Jul 25, 2022.
benluo cbad07c
Merge branch 'scala:main' into main
benluo f524cce
Update _zh-cn/overviews/scala3-book/control-structures.md
benluo 774fa7d
Update _zh-cn/overviews/scala3-book/domain-modeling-tools.md
benluo d64054f
Update _zh-cn/overviews/scala3-book/domain-modeling-tools.md
benluo e216375
changed according to review on Jul 28, 2022.
benluo 3008f7c
Merge branch 'scala:main' into main
benluo 6e7daca
Merge branch 'scala:main' into main
benluo 2f5c1db
add scala4x.css in fold. Add next in scala-features.md
benluo 65a6a01
Merge branch 'scala:main' into main
benluo 4eb239a
Merge branch 'scala:main' into main
benluo 6549731
Merge branch 'scala:main' into main
benluo 2decccc
Update _zh-cn/overviews/scala3-book/domain-modeling-fp.md
benluo 0051e8b
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo 6c267bf
Update _zh-cn/overviews/scala3-book/fun-write-map-function.md
benluo a523765
Update _zh-cn/overviews/scala3-book/fun-write-map-function.md
benluo 4073ced
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo 5a1aa41
Update _zh-cn/overviews/scala3-book/scala-for-java-devs.md
benluo 07192cf
Update _zh-cn/overviews/scala3-book/taste-objects.md
benluo 40f3e2c
changed all review.
benluo 5ff7904
Merge branch 'scala:main' into main
benluo c080bac
Merge branch 'scala:main' into main
benluo ce11fd7
Merge branch 'scala:main' into main
benluo e908683
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo bf18649
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo 3db8200
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo 349b19d
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo 0ef10ad
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo 850bee6
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo 1cf9b12
all have been changed according to review.
benluo 67699a2
Merge branch 'scala:main' into main
benluo 4e32489
changed term and delete "next-page" in scala-features.md
benluo 60e8684
Merge branch 'scala:main' into main
benluo ba6db33
Merge branch 'scala:main' into main
benluo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
--- | ||
title: Collections | ||
type: section | ||
description: This page provides a high-level overview of the main features of the Scala 3 programming language. | ||
num: 13 | ||
previous-page: taste-objects | ||
next-page: taste-contextual-abstractions | ||
--- | ||
|
||
|
||
Scala 库具有一组丰富的集合类,这些类具有一组丰富的方法。 | ||
集合类有不可变和可变两种形式。 | ||
|
||
## 创建列表 | ||
|
||
为了让您了解这些类的工作原理,下面是一些使用 `List` 类的示例,该类是不可变的链接列表类。 | ||
这些示例显示了创建填充的 `List` 的不同方法: | ||
|
||
```scala | ||
val a = List(1, 2, 3) // a: List[Int] = List(1, 2, 3) | ||
|
||
// Range methods | ||
val b = (1 to 5).toList // b: List[Int] = List(1, 2, 3, 4, 5) | ||
val c = (1 to 10 by 2).toList // c: List[Int] = List(1, 3, 5, 7, 9) | ||
val e = (1 until 5).toList // e: List[Int] = List(1, 2, 3, 4) | ||
val f = List.range(1, 5) // f: List[Int] = List(1, 2, 3, 4) | ||
val g = List.range(1, 10, 3) // g: List[Int] = List(1, 4, 7) | ||
``` | ||
|
||
## `List`方法 | ||
|
||
拥有填充的列表后,以下示例将显示可以对其调用的一些方法。 | ||
请注意,这些都是函数式方法,这意味着它们不会改变调用的集合,而是返回包含更新元素的新集合。 | ||
每个表达式返回的结果显示在每行的注释中: | ||
|
||
```scala | ||
// a sample list | ||
val a = List(10, 20, 30, 40, 10) // List(10, 20, 30, 40, 10) | ||
|
||
a.drop(2) // List(30, 40, 10) | ||
a.dropWhile(_ < 25) // List(30, 40, 10) | ||
a.filter(_ < 25) // List(10, 20, 10) | ||
a.slice(2,4) // List(30, 40) | ||
a.tail // List(20, 30, 40, 10) | ||
a.take(3) // List(10, 20, 30) | ||
a.takeWhile(_ < 30) // List(10, 20) | ||
|
||
// flatten | ||
val a = List(List(1,2), List(3,4)) | ||
a.flatten // List(1, 2, 3, 4) | ||
|
||
// map, flatMap | ||
val nums = List("one", "two") | ||
nums.map(_.toUpperCase) // List("ONE", "TWO") | ||
nums.flatMap(_.toUpperCase) // List('O', 'N', 'E', 'T', 'W', 'O') | ||
``` | ||
|
||
这些示例显示了如何使用 `foldLeft` 和 `reduceLeft` 方法来对整数序列中的值求和: | ||
|
||
```scala | ||
val firstTen = (1 to 10).toList // List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | ||
|
||
firstTen.reduceLeft(_ + _) // 55 | ||
firstTen.foldLeft(100)(_ + _) // 155 (100 is a “seed” value) | ||
``` | ||
|
||
Scala 集合类还有更多可用的方法,它们在[集合章节][collections]和 [API 文档][api]中进行了演示。 | ||
|
||
## 元组 | ||
|
||
Scala _元组_ 是一种类型,可让您轻松地将不同类型的集合放在同一个容器中。 | ||
例如,给定以下 `Person` 样例类: | ||
|
||
```scala | ||
case class Person(name: String) | ||
``` | ||
|
||
这是演示你如创建一个元组,这个元组包含 `Int`, `String`, 和定制的 `Person` 值: | ||
|
||
```scala | ||
val t = (11, "eleven", Person("Eleven")) | ||
``` | ||
|
||
有元组后,可以通过将其值绑定到变量来访问,也可以通过数字访问它们: | ||
|
||
```scala | ||
t(0) // 11 | ||
t(1) // "eleven" | ||
t(2) // Person("Eleven") | ||
``` | ||
|
||
您还可以使用以下 _解析器_ 的办法将元组字段分配变量名: | ||
|
||
```scala | ||
val (num, str, person) = t | ||
|
||
// result: | ||
// val num: Int = 11 | ||
// val str: String = eleven | ||
// val person: Person = Person(Eleven) | ||
``` | ||
|
||
有些情况更适合使用元组, 那就是当你想要将异构类型的集合放在一个小的类似集合的结构中。 | ||
有关更多元组详细信息,请参阅 [参考文档][reference]。 | ||
|
||
[collections]: {% link _overviews/scala3-book/collections-intro.md %} | ||
[api]: https://scala-lang.org/api/3.x/ | ||
[reference]: {{ site.scala3ref }}/overview.html |
54 changes: 54 additions & 0 deletions
54
_zh-cn/overviews/scala3-book/taste-contextual-abstractions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Contextual Abstractions | ||
type: section | ||
description: This section provides an introduction to Contextual Abstractions in Scala 3. | ||
num: 14 | ||
previous-page: taste-collections | ||
next-page: taste-toplevel-definitions | ||
--- | ||
|
||
|
||
{% comment %} | ||
TODO: Now that this is a separate section, it needs a little more content. | ||
{% endcomment %} | ||
|
||
在某些情况下,可以省略在方法调用中你认为是重复的的某些参数。 | ||
|
||
这些参数之所以称为 _上下文参数_,是因为它们是由编译器从方法调用周围的上下文中推断出来的。 | ||
|
||
例如,考虑一个程序,该程序按两个条件对地址列表进行排序:城市名称,然后是街道名称。 | ||
|
||
```scala | ||
val addresses: List[Address] = ... | ||
|
||
addresses.sortBy(address => (address.city, address.street)) | ||
``` | ||
|
||
`sortBy` 方法调用一个函数,该函数为每个地址返回值,这个值会用来与其他地址比较。 | ||
在本例中,我们传递一个函数,该函数返回一对,该对包含城市名称和街道名称。 | ||
|
||
请注意,我们只指示 _怎么_ 比较的,而不是 _如何_ 来执行比较。 | ||
排序算法如何知道如何比较 `String` 对的? | ||
|
||
实际上,`sortBy` 方法采用第二个参数---一个上下文参数---该参数由编译器推断。 | ||
它不会出现在上面的示例中,因为它是由编译器提供的。 | ||
|
||
第二个参数实现 _如何_ 进行比较。 | ||
省略它很方便,因为我们知道 `String` 通常使用词典顺序进行比较。 | ||
|
||
但是,也可以显式传递它: | ||
|
||
```scala | ||
addresses.sortBy(address => (address.city, address.street))(using Ordering.Tuple2(Ordering.String, Ordering.String)) | ||
``` | ||
|
||
在本例中,`Ordering.Tuple2(Ordering.String, Ordering.String)` 实例正是编译器以其他方式推断的实例。 | ||
换句话说,这两个示例生成相同的程序。 | ||
|
||
_上下文抽象_ 用于避免重复代码。 | ||
它们帮助开发人员编写可扩展且同时简洁的代码段。 | ||
|
||
有关更多详细信息,请参阅本书的[上下文抽象章节][contextual],以及[参考文档][reference]。 | ||
|
||
[contextual]: {% link _overviews/scala3-book/ca-contextual-abstractions-intro.md %} | ||
[reference]: {{ site.scala3ref }}/overview.html |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.