O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required