Filtering operators
Filtering operators act as the where
operators of any LINQ
query. They reduce, take, or peek a value (or multiple values) from a sequence when messages comply with a given filtering function.
Filter
The easiest filtering operator, filter, simply applies a filtering condition that allows or prevents messages from flowing throughout the newly created sequence. In Rx, the filter operator in made by using the Where
extension method like in any other LINQ
query.
Here's an example:
var s12 = new Subject<string>(); var filtered = s12.Where(x => x.Contains("e")); filtered.Subscribe(Console.WriteLine); s12.OnNext("Mr. Brown"); s12.OnNext("Mr. White");
Distinct
The distinct
operator, similar to what happens in any SQL statement, creates a new sequence that prevents duplicated values from flowing out from the source sequence.
Here's an example:
var s13 = new...