Tutorial by Examples

Install the NuGet package System.Reactive, then add this using statement to access the Rx extension methods: using System.Reactive.Linq;
emails.Where(email => email.From == "John")
Subscription returns an IDisposable: IDisposable subscription = emails.Subscribe(email => Console.WriteLine("Email from {0} to {1}", email.From, email.To)); When you are ready to unsubscribe, simply dispose the subscription: subscription.Dispose();
emails.Subscribe(email => Console.WriteLine("Email from {0} to {1}", email.From, email.To), cancellationToken);
Given an async method like this: Task<string> GetNameAsync(CancellationToken cancellationToken) Wrap it as an IObservable<string> like this: Observable.FromAsync(cancellationToken => GetNameAsync(cancellationToken))
Given an IObservable<Offer> of offers from merchants to buy or sell some type of item at a fixed price, we can match pairs of buyers and sellers as follows: var sellers = offers.Where(offer => offer.IsSell).Select(offer => offer.Merchant); var buyers = offers.Where(offer => offer.Is...
This code will subscribe to the emails observable twice: emails.Where(email => email.From == "John").Subscribe(email => Console.WriteLine("A")); emails.Where(email => email.From == "Mary").Subscribe(email => Console.WriteLine("B")); To share a...
Reactive Extensions are published on both NuGet and MyGet. Installing and using them is therefore the same as any other NuGet package: Install-Package System.Reactive NB package names changed between v2 and v3. See the README on Github for more info Breaking changes The NuGet packages have...
Let's say you need to implement an automatic search box, but the search operation is somewhat costly, like sending a web request or hitting up a database. You may want to limit the amount of search being done. For example, the user is typing "C# Reactive Extensions" in the search box : I...
There are two operators for filtering duplicates: emails.Distinct(); // Never see the same value twice emails.DistinctUntilChanged(); // Never see the same value twice in a row You can also pass in a predicate: emails.DistinctUntilChanged(x => x.Length); // Never see the same length email t...
Suppose you have a hot observable for which you would love to keep the count of. It could be the IObservable<StockTick> and you want to keep count of the average trade volume. You can use Scan for that. var tradeVolume = stockTicks.Select(e => e.Price) .Scan(0.0m, (aggregated, newtick...

Page 1 of 1