title: Single that emits a value that passed function returned
body: <p>I want a Single that calls a certain function and then completes with the value that function has returned.</p>
  
  <p>The following is something similar:</p>
  
  <pre><code>Single.fromCallable(this::func);
  </code></pre>
  
  <p>The problem with that is that it calls this::func every time a subscriber is added. So if this::func counts calls that single would return 3 to a third subscriber it gets.
  <br>
  I see that as a problem, because, what if this::func were a long running operation.
  <br>
  And I don't get it, does that mean that Single::onComplete has been called twice? Which I thought it was impossible, and it doesn't make sense, because, how can something complete twice?</p>
  
  <p>And since I'm an Android programmer Single::fromFuture doesn't work here, is there some alternative to it?</p>
  
  <p>I will demonstrate my problem with the following example:</p>
  
  <pre><code>class SingleFromCallableTest {
  
      int funcCalls = 0;
  
      int func(){
          return funcCalls++;
      }
  
      @Test
      public void run(){
          Single&lt;Integer&gt; source = Single.fromCallable(this::func);
          source.subscribe(System.out::println);  // prints 1
          source.subscribe(System.out::println);  // prints 2
      }
  }
  </code></pre>
  
  <p>IMO, second subscriber shouldn't have been called because Single should succed just once IMO.
  Just like with SingleSubject, once you call onSuccess, it cannot succed again.<br></p>
  
  <p>If <code>Single.fromCallable</code> would work the way it think it should, than, in the previouse example, <code>source</code> could have completed even before the first subscriber subscribed, which means that, only the following way of subscribing would make sense:</p>
  
  <pre><code>Single.fromCallable(this::func).subscribe(System.out.println);
  </code></pre>
  
  <p>But actually, maybe even then it's possible not to catch a value emited by single, maybe that's way this is not possible.</p>