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

Transducers: JavaScript 中高效的数据处理 pipeline #4950

Conversation

Raoul1996
Copy link
Contributor

译文翻译完成,resolve #4844

Change-Id: Ie3b30dd3203c2ca2f94736fed7c2fb1e8a69bad5
@Raoul1996 Raoul1996 force-pushed the translation/functional-programming-javascript-transducers branch from aac47b2 to 1ca0ae8 Compare January 4, 2019 18:05
@Raoul1996 Raoul1996 changed the title translation complete Transducers: JavaScript 中高效的数据处理 pipeline Jan 4, 2019
@leviding leviding added the 前端 label Jan 5, 2019
@EquinoxHzXu
Copy link
Contributor

校对认领

@fanyijihua
Copy link
Collaborator

@ElizurHz 好的呢 🍺


Transducers are:
* 可组合使用的简单功能集合
* 对大型集合或者无限流有效:不管管道中的操作数量有多少,都只对单一元素进行一次枚举。
Copy link
Contributor

Choose a reason for hiding this comment

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

这边已经把 pineline 翻译成管道了,全文是否要保留 pipeline 的英文需要统一下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

Transducers do much the same thing, but unlike ordinary reducers, transducers are composable using normal function composition. In other words, you can combine any number of transducers to form a new transducer which links each component transducer together in series.

Normal reducers can’t compose, because they expect two arguments, and only return a single output value, so you can’t simply connect the output to the input of the next reducer in the series. The types don’t line up:
普通的 reducer 不能这样(组合)。因为它需要两个参数,只返回一个输出值。所以你不能简单地将输出连接到串联中下一个 reducer 的输入。类型不符合:
Copy link
Contributor

Choose a reason for hiding this comment

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

类型不符合: => 这会出现类型不符合的情况:

直译看着有点突兀,建议自己添加些成分组成完整的句子


A transducer could map numbers to strings, or objects to arrays, or arrays to smaller arrays, or not change anything at all, mapping `{ x, y, z } -> { x, y, z }`. Transducers may also filter parts of the signal out of the stream `{ x, y, z } -> { x, y }`, or even generate new values to insert into the output stream, `{ x, y, z } -> { x, xx, y, yy, z, zz }`.
Transducer 可以将数字映射(mapping)成字符串,或者将对象映射到数组,或者将数组映射成更小的数组,或者根本不做任何改变,映射 `{ x, y, z } -> { x, y, z }`。传感器可以过滤流中的部分信号 `{ x, y, z } -> { x, y }`,甚至可以生成新值插入到输出流中,`{ x, y, z } -> { x, xx, y, yy, z, zz }`
Copy link
Contributor

Choose a reason for hiding this comment

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

Transducer 要翻译成 “传感器”,还是要保留英文,如果是数学、程序、代码相关的名词,在全文中要统一一下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个我改一下,太多了疏忽了


In the 1960s, groundbreaking work was happening in graphical computing in MIT’s Lincoln Laboratory using the TX-2 computer system, a precursor to the US Air Force SAGE defense system. Ivan Sutherland’s famous [Sketchpad](https://dspace.mit.edu/handle/1721.1/14979), developed in 1961–1962, was an early example of object prototype delegation and graphical programming using a light pen.
在 20 世纪 60 年代,麻省理工学院林肯实验室的图形计算开始使用TX-2计算机系统,这是美国空军SAGE防御系统的前身。 Ivan Sutherland 著名的 [Sketchpad](https://dspace.mit.edu/handle/1721.1/14979),于 1961 年至 1962 年开发,是使用光笔进行对象原型委派和图形编程的早期例子。
Copy link
Contributor

Choose a reason for hiding this comment

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


More recently, transducers have been independently rediscovered and a _different protocol_ developed for Clojure by **Rich Hickey** (circa 2014), who is famous for carefully selecting words for concepts based on etymology. In this case, I’d say he nailed it, because Clojure transducers fill almost exactly the same niche as transducers in SICP, and they share many common characteristics. However, they are _not strictly the same thing._
最近,transducer 已经重新被独立发现。并且 **Rich Hickey**(大约 2014 年)为 Clojure 开发了一个**不同的协议**,他以精心选择基于词源的概念词而闻名。这时,我就会说他说的太棒了,因为 Clojure 的 transducer 的内在基本和 SICP 中的相同,并且他们也具有了很多共性。但是,他们**并非严格相同。**
Copy link
Contributor

Choose a reason for hiding this comment

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

重新被独立发现 => 重新被独立发掘

@@ -298,17 +293,16 @@ const result = [1,2,3,4,5,6].reduce(xform, []); // [4, 8, 12]

console.log(result);
```
吸收很多东西。让我们分解一下。`map` 将函数应用于某些上下文的值。在这种情况下,上下文是 transducer pipeline。看起来大致如下:
Copy link
Contributor

Choose a reason for hiding this comment

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

吸收很多东西 => 这包括了很多内容

直译的意思不太对

@@ -227,53 +223,52 @@ const result = tempResult.map(double);
console.log(result);
// [4, 8, 12]
```
另一种方法是将值直接从过滤后的输出流式传输到 mapping 转换,而无需在其间创建和迭代临时数组。将值一次一个地流过,无需在转换过程中对每个阶段迭代相同的集合,并且 transducer 可以随时发出停止信号,这意味着你不需要在集合中更深入地计算每个阶段。需要产生所需的值。
Copy link
Contributor

Choose a reason for hiding this comment

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

mapping transformation 是否可以翻译成 “映射变换” ?


The part we care about is `a = step()` in the function signature. If there is no value for `a` (the accumulator), we'll create one by asking the next reducer in the chain to produce it. Eventually, it will reach the end of the pipeline and (hopefully) create a valid initial value for us.
记住这条规则:当没有参数调用时,reducer 应该总是为减少返回一个有效的初始(空)值。对于任何 reducer 函数,包括 React 或 Redux 的 Reducer,遵守此规则通常是个好主意。
Copy link
Contributor

Choose a reason for hiding this comment

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

这里的 reduction 应该指的是“reducer 的操作”,而不是直译的“减少”


In other words, if you have more state to flush after the previous function has signaled that it’s finished reducing, the completion step is the time to handle it. At this stage, you can optionally:
换句话说,如果在前一个函数表示已完成 reducing 后有更多状态需要刷新,则完成函数是处理它的时间。在此阶段,你可以选择:
Copy link
Contributor

Choose a reason for hiding this comment

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

在前一个函数表示已完成 reducing 后 => 在前一个函数得到 reducer 已完成的信号后

如果保留 reducer 和 reduce 的英文,建议部分的 reducing、reduced、reduction 等派生词可以以这两个词派生的短语作为中文翻译内容,更容易让人理解

const concatArray = (a, c) => a.concat([c]);
```

Now we can use the curried `transduce()` to create a partial application that transduces to arrays:
现在我们可以使用 curried `transduce()` 创建一个转换为数组的部分应用程序:
Copy link
Contributor

Choose a reason for hiding this comment

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

curried 的 => 柯里化的

@Yangfan2016
Copy link

@leviding 校对认领

@fanyijihua
Copy link
Collaborator

@Yangfan2016 妥妥哒 🍻

> * 校对者:

# Transducers: Efficient Data Processing Pipelines in JavaScript
# Transducers: JavaScript 中高效的数据处理 pipeline

![](https://cdn-images-1.medium.com/max/2000/1*uVpU7iruzXafhU2VLeH4lw.jpeg)

Choose a reason for hiding this comment

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

![图片提示](https://cdn-images-1.medium.com/max/2000/1*uVpU7iruzXafhU2VLeH4lw.jpeg)
建议加上图片提示,优化用户体验

> * 校对者:

# Transducers: Efficient Data Processing Pipelines in JavaScript
# Transducers: JavaScript 中高效的数据处理 pipeline

Choose a reason for hiding this comment

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

pipeline => Pipelines
这里应该和原文统一下(大小写,单复数形式)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里我在翻译的时候在单复数问题上有些纠结。一般在中文中没有明确体现单复数的做法,所以这里我当时倾向于用单数


1. This only works for arrays. What about potentially infinite streams of data coming in from a network subscription, or a social graph with friends-of-friends?
1. 这仅仅只适用于数组。对于那些些来自网络订阅的潜在无限数据流,或者朋友的朋友的社交图如何处理呢?

Choose a reason for hiding this comment

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

那些些 => 那些


Ivan’s brother, William Robert “Bert” Sutherland was one of several pioneers in data flow programming. He built a data flow programming environment on top of Sketchpad, which described software “procedures” as directed graphs of operator nodes with outputs linked to the inputs of other nodes. He wrote about the experience in his 1966 paper, [“The On-Line Graphical Specification of Computer Procedures”](https://dspace.mit.edu/handle/1721.1/13474). Instead of arrays and array processing, everything is represented as a stream of values in a continuously running, interactive program loop. Each value is processed by each node as it arrives at the parameter input. You can find similar systems today in [Unreal Engine’s Blueprints Visual Scripting Environment](https://docs.unrealengine.com/en-us/Engine/Blueprints) or [Native Instruments’ Reaktor](https://www.native-instruments.com/en/products/komplete/synths/reaktor-6/), a visual programming environment used by musicians to build custom audio synthesizers.
Ivan 的兄弟 William Robert “Bert” Sutherland 是数据流编程的几个先驱之一。他在 Sketchpad 上构建了一个数据流编程环境。它将软件“过程”描述为操作员节点的有向图,其输出连接到其他节点的输入。他在 1966 年的论文 [“The On-Line Graphical Specification of Computer Procedures”](https://dspace.mit.edu/handle/1721.1/13474) 中写下了这段经历。在连续运行的交互式程序循环中,所有内容都表示为值的流,而不是数组和处理中的数组。每个节点在到达参数输入时处理每个值。你现在可以在[虚拟蓝图引擎 Visual Scripting Environment](https://docs.unrealengine.com/en-us/Engine/Blueprints) [Native Instruments’ Reaktor](https://www.native-instruments.com/en/products/komplete/synths/reaktor-6/) 找到类似的系统,这是一种音乐家用来构建自定义音频合成器的可视化编程环境。

![](https://cdn-images-1.medium.com/max/800/1*nAe0WLXecnMGNalPclnFfw.png)

Choose a reason for hiding this comment

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

建议加上图片提示,优化用户体验

* Pull: lazy evaluation, or
* Push: eager evaluation
* Pull: 惰性求值,或者
* Push: 热切求值

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.

热切求值、及早求值都是可以的,即时求值不太好

> * 校对者:

# Transducers: Efficient Data Processing Pipelines in JavaScript
# Transducers: JavaScript 中高效的数据处理 pipeline

Choose a reason for hiding this comment

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

建议标题可以翻译为:
Pipelines,高效的数据处理方式 -- Javascript 篇
😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个我并不是很想这么翻译,因为这个系列文章的标题差不多都是这种调性😲

@Yangfan2016
Copy link

@Raoul1996 @leviding 校对完成

@Raoul1996
Copy link
Contributor Author

@leviding leviding merged commit 0fa33f5 into xitu:master Jan 8, 2019
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.

Transducers: JavaScript 中高效的数据处理 pipeline
5 participants