烂翻译系列之Rx.NET介绍第二版——第三部分——实战

The first part of this book focused on the basic ideas and types of Rx. In the second part, I showed the operators Rx offers, enabling us to define the transformations and computations we want to apply to our source data. This second part was essentially functional programming. Rx's operators are mostly like mathematical functions, in that they will invariably behave in the same way for particular inputs. They are unaffected by the state of the world around them, and they also do nothing to change its state. In functional programming, such mechanisms are sometimes described as pure.

本书的第一部分重点介绍了Rx的基本概念和类型。在第二部分中,我展示了Rx提供的运算符,这些运算符使我们能够定义想要应用于源数据的转换和计算。这第二部分本质上是函数式编程的体现。Rx的运算符大多类似于数学函数,因为它们对于特定输入总会产生相同的行为方式。它们不受周围环境状态的影响,也不会改变环境的状态。在函数式编程中,这种机制有时被称为"纯"函数。

This purity can help us understand what our code will do. It means we don't need to know about the state of the rest of our program in order to understand how one particular part functions. However, code that is completely detached from the outside world is unlikely to achieve anything useful. In practice, we need to connect these pure computations with more pragmatic concerns. The Creating Observable Sequences chapter already showed how to define observable streams, so we've already looked at how to connect real world inputs into the world of Rx. But what about the other end? How do we do something useful with the results of our processing?

这种"纯"特性有助于我们理解代码的行为。它意味着,为了理解某个特定部分的功能,我们无需了解程序中其他部分的状态。然而,完全脱离外部世界的代码不太可能实现任何有价值的功能。在实践中,我们需要将这些纯计算与实际需求相结合。在《创建可观察序列》一章中,我们已经展示了如何定义可观察流,因此我们已经探讨了如何将现实世界的输入接入Rx的世界中。但另一端呢?我们该如何利用处理结果实现有用的功能呢?

In some cases, it might be enough to do work inside IObserver implementations, or using the callback-based subscription mechanisms you've already seen. However, some situations will demand something more sophisticated. So in this third part of the book, we will look at some of the features Rx offers to help connect processes of the kind we looked at in part 2 with the rest of the world.

在某些情况下,仅仅在 IObserver 接口的实现内部处理工作,或者使用您已经掌握的基于回调的订阅机制可能就足够了。然而,某些场景会要求更复杂的解决方案。因此,在本书的第三部分中,我们将探讨Rx提供的一些功能,这些功能能够帮助我们将在第二部分中介绍的那类处理流程与外部世界进行连接。

posted @ 2024-09-03 17:07  菜鸟吊思  阅读(6)  评论(0)    收藏  举报