Skip to content
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

TypeScript 中带生成器的惰性管道 #6694

Conversation

febrainqu
Copy link
Contributor

译文翻译完成,resolve #6675

TypeScript中带生成器的惰性管道
@lsvih lsvih changed the title TypeScript中带生成器的惰性管道 TypeScript 中带生成器的惰性管道 Feb 10, 2020
@GJXAIOU
Copy link

GJXAIOU commented Feb 23, 2020

校对认领

@lsvih
Copy link
Member

lsvih commented Mar 5, 2020

@GJXAIOU 校对怎么样啦?有空记得来看看哈

@xionglong58
Copy link
Contributor

@lsvih 校对认领

@fanyijihua
Copy link
Collaborator

@xionglong58 妥妥哒 🍻

Copy link
Contributor

@xionglong58 xionglong58 left a comment

Choose a reason for hiding this comment

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

@febrainqu @lsvih 只校对了部分内容,大致意思翻译到了,需要再做调整,后面再来校对,译者辛苦啦


![Photo by [Quinten de Graaf](https://unsplash.com/@quinten149?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)](https://cdn-images-1.medium.com/max/9704/1*wEQnHaPoHc_QJo5vxwrCEg.jpeg)

In recent years the JavaScript community has embraced the functional array methods like `map` and `filter`. Writing for-loops has become something that gets associated with 2015 and JQuery. But the array methods in JavaScript are far from ideal when we are talking about performance. Lets look at an example to clarify the issues:
近年来,JavaScript 社区已经接受了函数数组方法,例如 `map` `filter`。 编写 for 循环已经成为与2015年和 JQuery 相关的内容。但是在性能方面,JavaScript 中的数组方法远远达不到预期。让我们看一个例子来说明这些问题:
Copy link
Contributor

Choose a reason for hiding this comment

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

functional =>函数式


![Photo by [Quinten de Graaf](https://unsplash.com/@quinten149?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)](https://cdn-images-1.medium.com/max/9704/1*wEQnHaPoHc_QJo5vxwrCEg.jpeg)

In recent years the JavaScript community has embraced the functional array methods like `map` and `filter`. Writing for-loops has become something that gets associated with 2015 and JQuery. But the array methods in JavaScript are far from ideal when we are talking about performance. Lets look at an example to clarify the issues:
近年来,JavaScript 社区已经接受了函数数组方法,例如 `map` `filter`。 编写 for 循环已经成为与2015年和 JQuery 相关的内容。但是在性能方面,JavaScript 中的数组方法远远达不到预期。让我们看一个例子来说明这些问题:
Copy link
Contributor

Choose a reason for hiding this comment

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

[编写 for 循环已经成为与2015年和 JQuery 相关的内容]=>for 循环已经成为过去式,或者只能在Jquery中见到。

* create a new array with the numbers filtered
* take the first item
* 创建一个含有五个元素的数组
* 创建是个每个数字乘2的新数组
Copy link
Contributor

Choose a reason for hiding this comment

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

创建一个新数组,元素时前一个数组对应元素的2倍。


This involves a lot more stuff happening then is actually needed. The only thing has to happen is that the first item that passes `x > 5` gets processed and returned. In other languages (like Python) iterators are used to solve this issue. Those iterators are a lazy collection and only processes data when it is requested. If JavaScript would use lazy iterators for its array methods the following would happen instead:
这涉及到比实际需要的更多的事情. 这里唯一必要的是处理并返回通过 `x > 5` 的第一项。 在其他语言中 (例如 Python),用迭代器来解决此类问题。 这些迭代器是一个惰性集合,只在请求时处理数据。 如果JavaScript将懒惰的迭代器用于其数组方法,则会发生以下情况:
Copy link
Contributor

Choose a reason for hiding this comment

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

翻译过于生硬了

[这涉及到比实际需要的更多的事情. 这里唯一必要的是处理并返回通过 x > 5 的第一项。]=>[实际上有很步骤是多余的,唯一必要的就是返回第一个大于 5 的元素。]


This involves a lot more stuff happening then is actually needed. The only thing has to happen is that the first item that passes `x > 5` gets processed and returned. In other languages (like Python) iterators are used to solve this issue. Those iterators are a lazy collection and only processes data when it is requested. If JavaScript would use lazy iterators for its array methods the following would happen instead:
这涉及到比实际需要的更多的事情. 这里唯一必要的是处理并返回通过 `x > 5` 的第一项。 在其他语言中 (例如 Python),用迭代器来解决此类问题。 这些迭代器是一个惰性集合,只在请求时处理数据。 如果JavaScript将懒惰的迭代器用于其数组方法,则会发生以下情况:
Copy link
Contributor

Choose a reason for hiding this comment

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

[JavaScript将懒惰]=>[JavaScript 将懒惰]

* `[0]` requests the first item from `filter`
* `filter` requests items from `map` until it has found one item that passes the predicate and yields (‘returns’) it
* `map` has processed an item for each time `filter` requested it
* `[0]` 从 `filter` 请求第一项
Copy link
Contributor

Choose a reason for hiding this comment

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

[[0]filter 请求第一项]=>'[0]'请求经 ‘filter’ 操作后数组的第一个元素。

* `map` has processed an item for each time `filter` requested it
* `[0]` `filter` 请求第一项
* `filter` `map` 中请求元素,直到发现一个符合条件的元素,并返回 (‘returns’)
* `map` 已经处理了每一次 `filter` 请求
Copy link
Contributor

Choose a reason for hiding this comment

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

[map 已经处理了每一次 filter 请求]=>每当 ‘filter’ 发送一次请求,‘map’ 便处理一个元素。


Luckily for us JavaScript does actually support the concept of [iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators). They can be created with [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) functions that yield the items of the collection. A generator function looks as follows:
幸运的是JavaScript确实支持[迭代器](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)的概念. 可以使用生成集合项的[生成器](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) 函数来创建它们。一个生成器函数如下:
Copy link

Choose a reason for hiding this comment

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

[幸运的是JavaScript确实支持]=>[幸运的是 JavaScript 确实支持]


The last part of the library is the public facing API. The library uses the builder pattern to allow you to chain methods like on arrays. This is done by creating a function that takes an iterator and returns an object with the methods on it. Those methods can call the constructor again with an updated iterator for the chaining:
库的最后一部分是面向公众的API。 该库使用构建器模式来允许您像在数组上那样链接方法。 这是通过创建一个接受迭代器并返回带有方法的对象的函数来完成的。 这些方法可以再次调用构造函数与更新迭代器的链接:
Copy link

Choose a reason for hiding this comment

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

[库的最后一部分是面向公众的API] =>[库的最后一部分是面向公众的 API]

@GJXAIOU
Copy link

GJXAIOU commented Mar 6, 2020

@febrainqu @Glowin 大致校对完成,文中有不少的英文 . 应该转换为中文 ,因为比较多没有逐个纠正。

@lsvih lsvih added enhancement 等待译者修改 and removed 正在校对 labels Mar 6, 2020
@febrainqu
Copy link
Contributor Author

@GJXAIOU @xionglong58 感谢校对,晚些时候会修改和自查的

@febrainqu
Copy link
Contributor Author

@GJXAIOU @xionglong58 已更新,麻烦两位看一下还有什么问题

@@ -5,11 +5,11 @@
> * 译者:
Copy link
Member

Choose a reason for hiding this comment

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

麻烦加一下译者和校对者的信息哈

@febrainqu
Copy link
Contributor Author

@lsvih 已添加

@lsvih
Copy link
Member

lsvih commented Mar 10, 2020

还是有很多符号问题,比如许多后面多了空格、,:()!等符号用了半角符号,与中文在一起的英文单词前后没空格等。请译者根据排版指南再修改一下,也麻烦 @GJXAIOU @xionglong58 二位校对再帮忙看看语句通顺的问题

@lsvih
Copy link
Member

lsvih commented Mar 10, 2020

格式没啥问题了👍稍晚点我试着把部分语句顺一顺

@lsvih lsvih added 标注 待管理员 Review and removed enhancement 等待译者修改 labels Mar 16, 2020
@lsvih
Copy link
Member

lsvih commented Apr 29, 2020

@febrainqu 抱歉拖了这么久,之前都忘了这事了。。

这是您翻译的第一篇文章,还是有很多提升空间的,因此我直接在您的原文基础上进行了修改,现在应该更加通顺且容易理解了,您可以参考一下。当然您之后翻译的文章质量都挺高的!

@lsvih lsvih merged commit a46b00c into xitu:master Apr 29, 2020
@lsvih
Copy link
Member

lsvih commented Apr 29, 2020

@febrainqu 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

@lsvih lsvih added 翻译完成 and removed 标注 待管理员 Review labels Apr 29, 2020
@febrainqu
Copy link
Contributor Author

@lsvih 已发布
地址:https://juejin.im/post/5eaa43616fb9a0432c4c8fc8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript 中带生成器的惰性管道
5 participants