Rx Operators

Many of the core LINQ operators that were introduced in Chapter 2 have their equivalent in Rx. Let's examine a few of the most common: take, skip, distinct, using, and zip.

Take

The Take operator allows you to specify how many objects you want from the collection. A small example makes this clear,

var input = new[] {1,2,3,4,5,4,3,2,1}.ToObservable(); var output = input.Take(5).Select(x => x * 10); output.Dump();

The Take operator limits the output of this Rx query to just the first five values. The following is the output:

10 20 30 40 50

Skip

We won't be surprised to learn that Skip allows you to skip over the first n items in the new collection. This can be particularly helpful when you want to skip over, for example, ...

Get Programming Reactive Extensions and LINQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.