Reactive Extension (Rx) tutorial that is up to date

C#.Netsystem.reactive

C# Problem Overview


I am quite interested in Reactive Extensions but I cannot find an up to date tutorial. I started with Curing the asynchronous blues with the Reactive Extensions for .NET but it is out of date. I can figure out some changes but I could not get many examples working.

I found many articles on the web, mainly from 2009,2010 but they are also incompatible with the current release. I am especially interested in using Rx with Windows Phone and WebClient:

WebClient wc = new WebClient();

var o = Observable.FromEvent<DownloadStringCompletedEventArgs>(wc, "DownloadStringCompleted").Select(newString => newString.EventArgs.Result);

// Subscribe to the observable, and set the label text
o.Subscribe(s => myLabel.Text = s);

// Start the download
wc.DownloadStringAsync(new Uri("http://www.data.com/service"));

Do not work anymore and replacing FromEvent with FromEventPattern is not enough.

Can somebody point me to an up to date resource?

C# Solutions


Solution 1 - C#

When learning Rx the first thing is to understand the philosophy behind IObservable and how it's push based nature compares with IEnumerable. I suggest the following one for a good explanation: A[nother] Simpler Tutorial for Reactive Extensions

Lee Campbell has nice series explaining the api and when to use them. He also tries to keep it up to date with latest releases: Reactive Extensions for .NET an Introduction The series is now available as a book at Introduction to Rx

By the way, I have also written a blog post about solving real life problem with rx: Using Reactive Extensions for Streaming Data from Database

Hope this helps.

Solution 2 - C#

I found a "learn by doing" project called Reactive Extensions (Rx) Koans.
It was last updated in March 2012, so it's fairly up-to-date.

> Definition of ‘Koan’   Kōans is a zen word meaning the enlightenment or awakening of a person, usually through a puzzle or riddle. The most common one is “What is the sound of one hand clapping?”

It is made of a series of almost-complete unit tests that you must finish in such a way that they pass. You do this by 'filling in the blanks'.

It's pretty neat, quite easy to complete, and gives valuable insight.

Oh yeah, and it's made by Bart De Smet from the Rx team.

Here's a typical unit test:

[TestMethod]
public void DoingInTheMiddle()
{
	var status = new List<String>();
	var daysTillTest = Range.Create(4, 1).ToObservable();
	daysTillTest.Do(d => status.Add(d + "=" + (d == 1 ? "Study Like Mad" : ___)))
                .Subscribe();
	Assert.AreEqual("[4=Party, 3=Party, 2=Party, 1=Study Like Mad]", status.AsString());
}

Solution 3 - C#

By far the best resource that helped me wrap my head around Rx is: http://www.introtorx.com/

I'm thinking this happens to a lot of people, but you can't find that site when searching on the keywords "Rx tutorial". Think somebody needs to add some tags to the site!

Solution 4 - C#

Read this online book line by line (every line) and practice. This is good, I did when I started with Rx.

http://www.introtorx.com/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIgor KulmanView Question on Stackoverflow
Solution 1 - C#GiorgiView Answer on Stackoverflow
Solution 2 - C#Cristian DiaconescuView Answer on Stackoverflow
Solution 3 - C#letstangoView Answer on Stackoverflow
Solution 4 - C#Gerald G.View Answer on Stackoverflow