title: How can I get the current value of a Subject exposed as an IObservable?
body: <p>I have a <code>User</code> model that has an <code>IObservable&lt;int&gt;</code> property. This property is backed by a <code>BehaviorSubject</code> that is initialized with a certain value. How can I get the current value of the observable, without having to expose another property that accesses the <code>.Value</code> property on the underlying <code>BehaviorSubject</code>?</p>
  
  <p>This is the sample model to consider:</p>
  
  <pre class="lang-cs prettyprint-override"><code>class User
  {
      private readonly BehaviorSubject&lt;int&gt; mySubject;
  
      public User()
      {
          mySubject = new BehaviorSubject&lt;int&gt;(100);
      }
  
      public IObservable&lt;int&gt; Value =&gt; mySubject.DistinctUntilChanged();
  
      public void SomeMethod(int level)
      {
          mySubject.OnNext(level);
      }
  }
  </code></pre>
  
  <p>Notice that I have a method that calls <code>OnNext</code> on the subject with the specified value. This is already strange to me, it would be better if I could just treat the <code>Value</code> observable as a get and set property but alas...</p>
  
  <p>On another part of my code, I need to imperatively get the current value for a given user, and I can't seem to find a way to do that from the <code>IObservable</code> interface directly. I tried using both the <code>Latest</code> and <code>MostRecent</code> methods, but they seem to do different things than what I would expect. When trying both, my application blocks indefinitely.</p>
  
  <p>The only way I found to properly expose the value was to create another property for the "current" value, like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public int CurrentValue =&gt; mySubject.Value;
  </code></pre>
  
  <p>I don't like this because it feels to me that I'm being redundant. Is there a better way to expose the current value of the observable so that external code can just get the value and do what it wants with it? For that matter, as I commented earlier, I'm also not very happy having another method to mutate the value. It makes the interface of the object cumbersome in my view. In knockoutjs for instance, I can get and set the value just by "calling" the observable, which seems simpler. In this case this would be equivalent to <code>Value()</code>.</p>