Skip to content

Composite Collections

Roland Pheasant edited this page Apr 5, 2016 · 9 revisions

Dynamic data previously has the capability of applying logic operators to reactive collections. For example, you could combine the results of multiple collections as follows.

var a = new SourceList<int>();
var b = new SourceList<int>();
var c = new SourceList<int>();

var inAll = a.Connect().Or(b.Connect()).Or(c.Connect());    //a logical OR
var inAny = a.Connect().And(b.Connect()).And(c.Connect());  //a logical AND
var inOnlyOne = a.Connect().Xor(b.Connect()).Xor(c.Connect());  //a logical Exclusive OR
var inFirstAndNotAnyOther = a.Connect().Except(b.Connect()).Except(c.Connect());  //a logical Except. i.e. items in a and not (b or c)

From version 4.6 you can now dynamically add or remove collections which are logically combined.

var list1 = new SourceList<int>();
var list2 = new SourceList<int>();
var list3  = new SourceList<int>();
	
var combined = new SourceList<ISourceList<int>>();

//child lists can be added or removed any time
combined.Add(list1);
combined.Add(list2);
combined.Add(list3);

//The operators look after themselves 
var inAll = combined.And();
var inAny = combined.Or();
var inOnlyOne= combined.Xor();
var inFirstAndNotAnyOther = combined.Except();

These operators produce an observable with the same signature as a single observable list. And even better than that, it is optimised to give the best possible performance.