Java Without If
Optionals are a huge step forward for Java, even if they aren&#x27;t perfect. They let you write interfaces that say &quot;I might not have an answer and if you don&#x27;t deal with it that&#x27;s your problem&quot;. That&#x27;s important.<p>That they also allow mapping, filtering, etc, isn&#x27;t about &#x27;removing ifs&#x27; or &#x27;hiding ifs&#x27; so much as they are about writing more readable code, imho.<p><pre><code>  Optional&lt;Foo&gt; myValue = gateway.callThatApi(...)
  return myValue.filter(Utils::isNotTooShabby)
                .map(this::mapToCoolerType)
                .map(getDecorator())
                .orElseThrow(new TotallyBlewItException())
</code></pre>
Is this perfect and beautiful? Nah. But it&#x27;s better than the 20 lines of Java 7 code I&#x27;d need to do the same thing. I&#x27;m able to write simple predicates and mapper functions as class variables, dynamically if I want, and call them in order as I like. It&#x27;s short, it&#x27;s descriptive rather than prescriptive. It isolates what I want from how I do it.<p>Debugging is annoying, yes, but I think there&#x27;s hope that a good pattern for it will be figured out by the community.