concept Distinct in category .net

appears as: Distinct
Rx.NET in Action

This is an excerpt from Manning's book Rx.NET in Action.

Note a few things in the example. First, it starts with the from . . . in clause and finishes with select; this is the standard structure. Second, not all operators can be embedded in the query expression syntax like Distinct. You’ll need to add them as method calls inside or outside the query expression. Generally, you can call any method inside the query expression. Eventually, the query expression is syntactic sugar provided by the compiler, but using it makes things much simpler, such as in the case of nested queries and joins.

The Distinct operator permits a restrictive policy on the resulting observable, so values appear only once in the sequence. If the observable emits news items that come from multiple news sources, but you want to see a news item only once, for example, the Distinct operator makes this easy to achieve, assuming the news item has an identifier. Figure 8.10 shows a marble diagram of Distinct.

Figure 8.10. The Distinct operator suppresses duplicate items emitted by an observable.

Note that the Distinct operator emits values as they come (and not when the source observable completes), unless they were already emitted:

In the output of this program the lines prefixed with Distinct are emitted by the observable after removing the duplicates (with the Distinct operator):