Skip to content

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 87 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
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 May 10, 2022
30add30
modify _zh-cn/scala3/new-in-scala3.md
benluo May 11, 2022
1c937b8
add _zh-cn/scala3/guides/tasty-overview.md
benluo May 11, 2022
3de24bc
Merge branch 'scala:main' into main
benluo May 12, 2022
770e5a7
Change _zh-cn/scala3/guides/tasty-overview.md
benluo May 13, 2022
3edca3b
add few chapters in _zh-cn/overviews/scala3-book
benluo May 16, 2022
adcf494
Merge branch 'scala:main' into main
benluo May 16, 2022
e732e9e
translated all tastes files. in scala3-book.
benluo May 17, 2022
f87d417
Merge branch 'scala:main' into main
benluo May 17, 2022
74405c5
modified according to review.
benluo May 17, 2022
4422ef0
Merge branch 'scala:main' into main
benluo May 18, 2022
313fdff
correct translation according review.
benluo May 18, 2022
300d5cd
Missed one translation. Finish all corrects.
benluo May 18, 2022
13c00a6
Merge branch 'scala:main' into main
benluo May 21, 2022
3f33fc4
add _zh-cn/overviews/scala3-book/first-look-at-types.md
benluo May 21, 2022
e10cf0d
add _zh-cn/overviews/scala3-book/control-structures.md
benluo May 21, 2022
3573d19
add two files as below
benluo May 22, 2022
d8cbad3
add _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo May 24, 2022
76f49ec
Merge branch 'scala:main' into main
benluo May 24, 2022
799b1f2
add and modified as below
benluo May 24, 2022
3dd2ec3
add all methods*
benluo May 24, 2022
66a752e
Merge branch 'scala:main' into main
benluo May 25, 2022
8390a95
add functions
benluo May 26, 2022
b48eb7c
add _zh-cn/overviews/scala3-book/packaging-imports.md
benluo May 28, 2022
6504fbf
Merge branch 'scala:main' into main
benluo May 28, 2022
c11754c
add all collections
benluo May 28, 2022
f751a72
add all fp files
benluo May 29, 2022
3098a0f
Merge branch 'scala:main' into main
benluo May 31, 2022
d811aba
add all types files
benluo Jun 5, 2022
b9c6ac0
add all types files
benluo Jun 5, 2022
d8ba669
Merge branch 'scala:main' into main
benluo Jun 5, 2022
a98a687
add all ca-* files
benluo Jun 8, 2022
aadcb0e
add concurrency.md
benluo Jun 10, 2022
b845934
Merge branch 'scala:main' into main
benluo Jun 10, 2022
bb47995
add all tools files
benluo Jun 11, 2022
4bb25d3
Merge branch 'scala:main' into main
benluo Jun 11, 2022
c59f3ba
add interacting-with-java.md
benluo Jun 11, 2022
76e08bf
add all scala-for-* files. Finish all files in Scala3-book.
benluo Jun 16, 2022
d3637fb
corrected broken link in concurrency.md
benluo Jun 16, 2022
4f3b6da
Merge branch 'scala:main' into main
benluo Jun 21, 2022
00e7ca6
Merge branch 'scala:main' into main
benluo Jun 25, 2022
8fa8ac4
Merge branch 'scala:main' into main
benluo Jul 1, 2022
585c7ac
Merge branch 'scala:main' into main
benluo Jul 4, 2022
47aab08
correct ca.* files
benluo Jul 4, 2022
de48d7e
Merge branch 'scala:main' into main
benluo Jul 15, 2022
00edb7d
Merge branch 'scala:main' into main
benluo Jul 17, 2022
ddcf921
modified translation according to review.
benluo Jul 17, 2022
951c842
Merge branch 'scala:main' into main
benluo Jul 19, 2022
7e54512
correct collections-classes.md
benluo Jul 19, 2022
86fdf8b
change translation according to review on Jul 19
Jul 21, 2022
fca798c
Merge branch 'scala:main' into main
benluo Jul 22, 2022
9cdf9fe
Merge branch 'scala:main' into main
benluo Jul 25, 2022
e387055
Merge branch 'scala:main' into main
benluo Jul 27, 2022
6a507ea
modified according to review on Jul 25, 2022.
benluo Jul 27, 2022
cbad07c
Merge branch 'scala:main' into main
benluo Jul 29, 2022
f524cce
Update _zh-cn/overviews/scala3-book/control-structures.md
benluo Jul 29, 2022
774fa7d
Update _zh-cn/overviews/scala3-book/domain-modeling-tools.md
benluo Jul 29, 2022
d64054f
Update _zh-cn/overviews/scala3-book/domain-modeling-tools.md
benluo Jul 29, 2022
e216375
changed according to review on Jul 28, 2022.
benluo Jul 29, 2022
3008f7c
Merge branch 'scala:main' into main
benluo Aug 3, 2022
6e7daca
Merge branch 'scala:main' into main
benluo Aug 10, 2022
2f5c1db
add scala4x.css in fold. Add next in scala-features.md
benluo Aug 10, 2022
65a6a01
Merge branch 'scala:main' into main
benluo Aug 14, 2022
4eb239a
Merge branch 'scala:main' into main
benluo Aug 17, 2022
6549731
Merge branch 'scala:main' into main
benluo Aug 19, 2022
2decccc
Update _zh-cn/overviews/scala3-book/domain-modeling-fp.md
benluo Aug 21, 2022
0051e8b
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo Aug 21, 2022
6c267bf
Update _zh-cn/overviews/scala3-book/fun-write-map-function.md
benluo Aug 21, 2022
a523765
Update _zh-cn/overviews/scala3-book/fun-write-map-function.md
benluo Aug 21, 2022
4073ced
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo Aug 21, 2022
5a1aa41
Update _zh-cn/overviews/scala3-book/scala-for-java-devs.md
benluo Aug 21, 2022
07192cf
Update _zh-cn/overviews/scala3-book/taste-objects.md
benluo Aug 21, 2022
40f3e2c
changed all review.
benluo Aug 21, 2022
5ff7904
Merge branch 'scala:main' into main
benluo Aug 24, 2022
c080bac
Merge branch 'scala:main' into main
benluo Aug 25, 2022
ce11fd7
Merge branch 'scala:main' into main
benluo Aug 28, 2022
e908683
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo Aug 28, 2022
bf18649
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo Aug 28, 2022
3db8200
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo Aug 28, 2022
349b19d
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo Aug 28, 2022
0ef10ad
Update _zh-cn/overviews/scala3-book/methods-most.md
benluo Aug 28, 2022
850bee6
Update _zh-cn/overviews/scala3-book/domain-modeling-oop.md
benluo Aug 28, 2022
1cf9b12
all have been changed according to review.
benluo Aug 28, 2022
67699a2
Merge branch 'scala:main' into main
benluo Sep 1, 2022
4e32489
changed term and delete "next-page" in scala-features.md
benluo Sep 2, 2022
60e8684
Merge branch 'scala:main' into main
benluo Sep 2, 2022
ba6db33
Merge branch 'scala:main' into main
benluo Sep 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions _zh-cn/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ scala3-sections:
- title: "第一步"
links:
- title: "Scala 3 中的新东西"
description: "Scala 3 现存新特性概览"
description: "Scala 3 中令人兴奋的新特性概览"
icon: "fa fa-star"
link: /scala3/new-in-scala3.html
- title: "快速开始"
description: "安装 Scala 3 并开始写些 Scala 代码"
description: "在你的电脑中安装 Scala 3,然后开始写些 Scala 代码"
icon: "fa fa-rocket"
link: /scala3/getting-started.html
- title: "Scala 3 书籍"
description: "一部介绍主要语言特性的线上书"
- title: "Scala 3 册子"
description: "通过一系列小课程来学习 Scala。"
icon: "fa fa-book"
link: /scala3/book/introduction.html
- title: "更多细节"
links:
- title: "迁移指引"
description: "一份帮你从 Scala 2 迁移到 Scala 3 的指引"
description: "一份帮你从 Scala 2 迁移到 Scala 3 的指引"
icon: "fa fa-suitcase"
link: /scala3/guides/migration/compatibility-intro.html
- title: "导览"
description: "关于语言特别之处的详细导览"
description: "关于语言特别之处的详细导览"
icon: "fa fa-map"
link: /zh-cn/scala3/guides.html
- title: "Scala 库 API"
description: "Scala 3 标准库API文档(多个小版本)"
description: "Scala 3 每一个版本的标准库API文档。"
icon: "fa fa-file-alt"
link: https://scala-lang.org/api/3.x/
- title: "语言参考手册"
description: "Scala 3 语言参考手册"
description: "Scala 3 语言参考手册"
icon: "fa fa-book"
link: https://docs.scala-lang.org/scala3/reference
- title: "贡献指南"
description: "Scala 3 编译器指南及如何贡献代码"
description: "Scala 3 编译器指南及如何修复问题"
icon: "fa fa-cogs"
link: /scala3/guides/contribution/contribution-intro.html
- title: "Scala 3 全新的 Scaladoc"
Expand Down Expand Up @@ -109,4 +109,8 @@ scala2-sections:
description: "Scala改进过程(Scala Improvement Process),语言及编译器进展"
icon: "fa fa-cogs"
link: /sips/index.html
- title: "为 Scala 作贡献"
description: "为 Scala 项目作贡献的完整指南"
icon: "fa fa-cogs"
link: /contribute/
---
108 changes: 108 additions & 0 deletions _zh-cn/overviews/scala3-book/taste-collections.md
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 _zh-cn/overviews/scala3-book/taste-contextual-abstractions.md
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
Loading