title: Guava Optional type, when transformation returns another Optional
body: <p>I have a method that procudes an <code>Optional&lt;String&gt;</code></p>
  
  <p>But this String must be parsed at another application level as Integer or Long.</p>
  
  <p>This I have a <code>Function&lt;String, Integer&gt;</code> that can be applied on the String, to produce an Integer. 
  This transformation can fail because the String may not be an Integer parsable value.</p>
  
  <hr>
  
  <p>I would like to return Optional when the transformation fails, instead of throwing a parsing exception.</p>
  
  <p>I can't make the STRING_TO_INTEGER_FUNCTION return null, because it is not allowed by Guava:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException: Transformation function cannot return null.
  </code></pre>
  
  <p>Thus the only thing I can do is having a <code>Function&lt;String,Optional&lt;Integer&gt;&gt;</code> but then I get as final result an <code>Optional&lt;Optional&lt;Integer&gt;&gt;</code> which isn't really cool because I may have another transformations to apply on it.</p>
  
  <hr>
  
  <p>Does someone know how can I do something like that in Guava?</p>
  
  <pre><code>Optional.of("Toto").transform(STRING_TO_INTEGER_FUNCTION) = // Optional&lt;Integer&gt; ?
  </code></pre>
  
  <p>Thanks</p>