Skip to content

Composite Collections

Christopher-Marcel Böddecker edited this page Oct 10, 2019 · 9 revisions

Dynamic data has always had 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 inAny = a.Connect().Or(b.Connect()).Or(c.Connect());    //a logical OR
var inAll = 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.

//child lists can be amended any time
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.

Exactly the same functionality and semantics apply to the observable cache.

Clone this wiki locally