Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to combine n observables dynamically into a list?
    primarykey
    data
    text
    <p>I have a collection of observables that generate state changes for a so-called <code>Channel</code>. And I have a <code>ChannelSet</code> that should monitor those channels.</p> <p>I would like to write something like this: if one channel is operational, the channel set is up, else, the channel set is down.</p> <pre><code>IEnumerable&lt;ChannelState&gt; channelStates = ...; if (channelStates.Any(cs =&gt; cs == ChannelState.Operational)) channelSet.ChannelSetState = ChannelSetState.Up; else channelSet.ChannelSetState = ChannelSetState.Down; </code></pre> <p>But where do I get my <code>IEnumerable&lt;ChannelState&gt;</code>? If I have 1 channel, I can simply subscribe to its state changes and modify the state of the channel set accordingly. For two channels, I could use <code>CombineLatest</code>:</p> <pre><code>Observable.CombineLatest(channel0States, channel1States, (cs0, cs1) =&gt; { if (cs0 == ChannelSetState.Up || cs1 == ChannelSetState.Up) return ChannelSetState.Up; else return ChannelSetState.Down; }); </code></pre> <p>But I have an <code>IEnumerable&lt;Channel&gt;</code> and a corresponding <code>IEnumerable&lt;IObservable&lt;ChannelState&gt;&gt;</code>. I'm looking for something like <code>CombineLatest</code> that is not limited to a fixed number of observables.</p> <p>To complicate matters, the collection of channels can be added to and removed from. So once in a while, a channel will be added for example. The new channel also generates state changes that need to be incorporated.</p> <p>So what I'm actually looking for is a function:</p> <pre><code>IEnumerable&lt;IObservable&lt;ChannelState&gt;&gt; --&gt; IObservable&lt;ChannelSetState&gt; </code></pre> <p>that keeps up-to-date when the input changes. There should be some way to accomplish this using Rx but I can't really figure out how.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload