Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guide to System.Reactive.Joins

I'm looking for an introduction/ some documentation of System.Reactive.Joins, which includes the Pattern, Plan, QueryablePattern and QueryablePlan classes. Google doesn't turn up anything ("System.Reactive.Joins"), MSDN has nothing, there are no samples here, and the excellent resources from this question do not cover this namespace.

Does anyone have some pointers?

like image 430
Matthew Finlay Avatar asked Mar 07 '12 05:03

Matthew Finlay


4 Answers

Found an excellent SO question that shows the usage, but to me the overall purpose of Plan and Pattern is to create a compositional unit of observable as opposed to a composed observable. Semantics, I know, but to me it seems a little easier to use this syntax then the various other "Join" methods. It allows you to separate the join from the projection altogether, so you can store intermediate plans and compose them with other observables whenever you want.

For example:

// Suppose we have observables o1, o2, ..., o9. 
// All IObservable<int>.

var o1and2 = o1.And(o2);  // Store this bad boy for later use. Pattern<int, int>

var o5and6and9 = o5
                .And(o6)
                .And(o9)
                .Then((t1, t2, t3) => t1 + t2 + t3);  // Plan<int>

var o3and7 = o3
            .And(o7)
            .Then((t1, t2) => string.Format("Result: {0}", t1 + t2)); // Plan<string>

var o12ando8and6 = o1and2
                  .And(o8)
                  .And(o6)
                  .Then((t1, t2, t3, t4) => ((decimal) t1, t2, t3.ToString(), t4));   
                  // Plan<(decimal, int, string, int)>

// "When" groups similar results together.
// It will fire when any of the Patterns give a result.

var obs1 = Observable
          .When(o1and2.Then((t1,t2) => t1+t2), o5and6and9); // IObservable<int>

var obs2 = Observable.When(o3and7);       // IObservable<string>
var obs3 = Observable.When(o12ando8and6); // IObservable<(decimal, int, string,int)>

SO Article: Reactive Extensions for .NET (Rx): Take action once all events are completed

Also, found an RX document that actually helped in understanding HOW to use this: http://www.clipcode.net/mentoring/RxReferenceLibrary.pdf [dead]

like image 80
SPFiredrake Avatar answered Oct 12 '22 15:10

SPFiredrake


This is the only thing I found: Join Patterns in Rx. I would also like to see other resources about these topics.

like image 40
Giorgi Avatar answered Oct 12 '22 15:10

Giorgi


Reactive Extensions for .NET (Rx) blogs.msdn.com

... then waits for the first two of three results to return using a join pattern.


How to join multiple IObservable sequences? stackoverflow.com

How about using the new Join operator in v.2838 ...


Introduction to the Reactive Extensions for JavaScript – New Release and Joins weblogs.asp.net

... Reactive Extensions for JavaScript which includes many of the changes I’ve been talking about lately including the third-party library integration, aggregates which I covered in the previous posts, and joins which is the subject of today’s post.


System.Reactive.Joins Namespace msdn.microsoft.com

Microsoft's definition of the System.Reactive.Joins Namespace.

like image 28
John Isaiah Carmona Avatar answered Oct 12 '22 14:10

John Isaiah Carmona


Other than the example I mentioned here (now updated to use Observable.When instead of Observable.Join), the general notion to me seems to be that you'd use When and join patterns when you want to compose the events themselves, rather than the contents of the events. So, I'd use the other query operators, like SelectMany, when I want to do something connected with the data being observed. When I want to do something purely in response to which events, and which patterns of events are firing in a particular order, then I would use join patterns. Now, that's not to say you can't combine the other query operators, say, Where and Select to filter and project out some values from an IObservable, which will later be used in a join pattern, but I think that's a good general way to look at it.

I did try to make some examples but I haven't really come up with anything better ... just more complicated cases of the same notion. You want to group related event patterns which may have complex relationships that make sense at the event level and not at the content of the IObservable.

like image 36
Richard Anthony Freeman-Hein Avatar answered Oct 12 '22 13:10

Richard Anthony Freeman-Hein