RX Example

Just an update to the doc with the Rx tutorial:

Newer versions of Rx need a small change to the source code:

Observable.FromEvent<EventArgs>(txt, "TextChanged")

Changes to

Observable.FromEventPattern<EventArgs>(txt, "TextChanged")

And the references are:

System.Reactive.Core
System.Reactive.Interfaces
System.Reactive.PlatformServices
System.Reactive.Linq
System.Reactive.Windows.Forms

Rx is available on Nuget
I found the example easier to understand by rewriting a couple of statements:

var textChanged = 
       from evt in Observable
          .FromEventPattern<EventArgs>(txt, "TextChanged") 
       select ((TextBox)evt.Sender).Text; 

var input = textChanged 
            .Throttle(TimeSpan.FromSeconds(1)) 
            .DistinctUntilChanged();

As

            
var input = Observable
            .FromEventPattern<EventArgs>(txt, "TextChanged")
            .Select(evt => ((TextBox)evt.Sender).Text)
            .Throttle(TimeSpan.FromSeconds(1))
            .DistinctUntilChanged();

And

var res = from term in input 
          from word in matchInWordNetByPrefix(term)
          .TakeUntil(input) 
          select word;

As

var res = input.SelectMany(t => matchInWordNetByPrefix(t)
               .TakeUntil(input));
This entry was posted in C# and tagged , . Bookmark the permalink.

Leave a Reply