I suspect that my understanding of what reactive extensions are is incorrect but I would have thought that they could be used to subscribe a method call to a collection. I'm thinking of a typical event handler in dotnet. My ultimate goal is to trigger a method call whenever the collection is modified.
I have the following small console application example, as you can see in the comments I was expecting it reprint the results or at least reprint the last result when it's added to the collection. I have also tried query.ToList() to see if re-running the query would print out the results again.
static void Main(string[] args)
{
// we have some data that is an IEnumerable It's lazy so we can query it.
IEnumerable<int> data = new List<int>();
for (int i = 0; i < 10; i++)
{
(data as List<int>).Add(i);
}
// create a linq query
var query = from number in data select number;
// create observable
IObservable<int> observableQuery = query.ToObservable<int>(Scheduler.Default);
observableQuery.Subscribe(Console.WriteLine);
/// the numbers get printed here 1.. 9
Console.ReadKey();
(data as List<int>).Add(1000);
var l = query.ToList();
var j = observableQuery.ToList();
// the numbers don't get reprinted here... ? Shouldn't they reprint when the collection is modified?
Console.ReadKey();
}