title: BehaviorSubject with defaultValue as Observable
body: <p>How can I provide a default value for <code>BehaviourSubject</code> as an <code>Observable</code>?</p>
  
  <p>So instead of:</p>
  
  <pre><code>// observer will receive the "default", "zero", "one"
  BehaviorSubject&lt;Object&gt; subject = BehaviorSubject.create("default");
  subject.subscribe(observer);
  subject.onNext("zero");
  subject.onNext("one");
  
  // observer2 will receive the "one", "two", "three"
  subject.subscribe(observer2);
  subject.onNext("two");
  subject.onNext("three");
  </code></pre>
  
  <p>It would be possible to do:</p>
  
  <pre><code>Observable&lt;Object&gt; defaultValueObservable = Observable.defer(new Func0&lt;Observable&lt;Object&gt;&gt;() {
  @Override public Observable&lt;Object&gt; call() {
      // simulate blocking work
      return Observable.just("blocking-default");
     }
  })
  
  // observer will receive the "blocking-default", "zero", "one"
  BehaviorSubject&lt;Object&gt; subject = BehaviorSubject.create(defaultValueObservable.first());
  subject.subscribe(observer);
  subject.onNext("zero");
  subject.onNext("one");
  
  // observer2 will receive the "one", "two", "three"
  subject.subscribe(observer2);
  subject.onNext("two");
  subject.onNext("three");
  </code></pre>
  
  <p>I understand, that first observer would wait for the calculation of the default value. I'm okay with paying that price.</p>
  
  <p>Basically, I want an in-memory repository. My current implementation idea:</p>
  
  <pre><code>public class Repository&lt;T&gt; {
      private final BehaviorSubject&lt;T&gt; subject;
  
      public Repository() {
          subject = BehaviorSubject.create();
      }
  
      public Observable&lt;T&gt; get() {
          assertUiThread();
          Observable&lt;T&gt; observable = subject.asObservable();
          if (subject.hasValue()) {
              return observable;
          } else {
              return observable.startWith(Observable.defer(new Func0&lt;Observable&lt;T&gt;&gt;() {
                  @Override public Observable&lt;T&gt; call() {
                      T t = getTfromBlockingSource();
                      return Observable.just(t);
                  }
              }));
          }
      }
  
      public void update(T t) {
          assertUiThread();
          subject.onNext(t);
      }
  }
  </code></pre>