title: How to combine multiple IObservable<bool> to form composite bool subscription value
body: <p>I would like to create a kind of Rx based ICommand for WPF. What I would like to do is to be able to control the CanExecute by combining ANY number of IObservable&lt;bool&gt; streams.</p>
  
  <p>The way I would like to work is that I would like to use the latest combined logically ANDed values of all of the predicates, and use that to control the bool  ICommand.CanExecute(object parameter) method implementation. I do not want to wait for all predicates to yield, it should use whatever one of the source predicate streams OnNexts (yields a value).</p>
  
  <p>I have got a bit stuck with trying to work out how to wire it up such that any of the predicates should cause the ICommand.CanExecute to yield a new value.</p>
  
  <p>Forgetting the actually ICommand implementation for a minute (as my question is more about the Rx side of things), can anyone suggest how I can wire up a bunch of predicates ( IObservable&lt;bool&gt;) that yield whenever the underlying things that create their streams change, but will also work in unison to create an overall end bool value that I can subscribe too. The end value would be a logical AND of the current predicate stream values.</p>
  
  <p>I am hoping I do not need to subscribe to all the predicate streams, and am hoping for a cool operator within RX that I may have overlooked.</p>
  
  <p>I know I can Merge streams, but that is not quite the behavior I am after, as that is just the latest value from the input streams that have been merged, I also know that I can CombineLatest, again this is not quite correct, as it will only yield when all the combined streams yield values.</p>
  
  <p>What I want is the streams to be combined so any change will notify a subscriber, but I also want to know what the logical ANDing of the combined predicate IObservable&lt;bool&gt; streams is right now, such that I can drive the ICommand.CanExecute from this overall combined value.</p>
  
  <p>I hope this makes sense.</p>
  
  <p>Here is some skeleton code (I have left some commented out code which shows the thinking behind my Rx Command idea, as it may help to illustrate what I want to get working)</p>
  
  <pre><code>public class ViewModel : INPCBase
  {
      private string title;
      private bool hasStuff;
  
      public ViewModel()
      {
          //Initialise some command with 1st predicate, and 
          // initial CanExecute value
          //SomeCommand = new ReactiveCommand(
          //    this.ObserveProperty(x =&gt; x.Title)
          //        .Select(x =&gt; !string.IsNullOrEmpty(x)), false);
          //SomeCommand.AddPredicate(this.ObserveProperty(x =&gt; x.HasStuff));
          //SomeCommand.CommandExecutedStream.Subscribe(x =&gt;
          //    {
          //        MessageBox.Show("Command Running");
          //    });
  
          IObservable&lt;bool&gt; obsPred = this.ObserveProperty(x =&gt; x.Title)
            .Select(x =&gt; !string.IsNullOrEmpty(x))
            .StartWith(!string.IsNullOrEmpty(this.Title));
          IObservable&lt;bool&gt; obsPred2 = this.ObserveProperty(x =&gt; 
            x.HasStuff).StartWith(this.HasStuff);
  
  
          obsPred.Merge(obsPred2).Subscribe(x =&gt;
              {
                  //How do I get this to fire whenever obsPred OR 
                  //obsPred2 fire OnNext, but also get a combined value (bool) 
                  //of the AND of obsPred &amp; obsPred2 (bearing in mind I may 
                  //want more than 2 predicates, it should cope with any number of
                  //IObservable&lt;bool&gt; predicates
              });
      }
  
      public string Title
      {
          get
          {
              return this.title;
          }
          set
          {
              RaiseAndSetIfChanged(ref this.title, value, () =&gt; Title);
          }
      }
  
  
      public bool HasStuff
      {
          get
          {
              return this.hasStuff;
          }
          set
          {
              RaiseAndSetIfChanged(ref this.hasStuff, value, () =&gt; HasStuff);
          }
      }
  
  }
  </code></pre>