title: Publish the last value of an observable
body: <p>I have a hot observable (a subject in this case):</p>
  
  <pre class="lang-js prettyprint-override"><code>var subject = new Rx.Subject();
  </code></pre>
  
  <p>I want to create another observable that every time a new subscriptions is being made immediately fires out the last value that was produced.</p>
  
  <p>So in pseudo code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var myObservableWithLastValue = subject.publishLast();
  
  subject.onNext(3);
  
  myObservableWithLastValue.subscribe(function(x){
      console.log(x); //should write 3
  });
  
  myObservableWithLastValue.subscribe(function(x){
      console.log(x); //should write 3, too
  });
  
  subject.onNext(4);
  
  myObservableWithLastValue.subscribe(function(x){
      console.log(x); //should write 4
  });
  </code></pre>
  
  <p>This is roughly what I want and it seems to work. However, I guess there must be some built in mechanism to achieve the same</p>
  
  <pre class="lang-js prettyprint-override"><code>Rx.Observable.prototype.keepLatest = function () {
      var latestValue;
  
      var disposable = this.subscribe(function (value) {
          latestValue = value;
      });
  
      return Rx.Observable.create(function (observer) {
          observer.onNext(latestValue);
          return disposable.dispose;
      });
  };
  </code></pre>