I have a collection of items that each have an IObserver, and a message source that produces Messages(!) I want to filter the messages, and only send on the relevant ones to each item. I think this is a good fit for System.Reactive's linq. Below is an example:
IObservable<Message> source;
foreach(item in items)
{
var filtered = from msg in source
where msg.Id == item.Id
selct msg;
filtered.Subscribe(item.Sink);
}
The problem is that when the source produces a message, the query is evaluated with respect to the last item
in the loop. So if there are twenty item
s each query will be against the properties of item
20.
How do I fix this?