title: How to properly implement this using Vavr?
body: <p>I would like got your advise on how to properly write this code on a functional way:</p>
  
  <pre><code>private Option&lt;CalcResult&gt; calculate(Integer X, Integer Y) {
      if (X &lt; Y) return Option.none();
      return Option.of( X + Y );
  } 
  
  public Option&lt;CalcResult&gt; otherMethod(Obj o) {
      if (o.getAttr()) {
        // getA() &amp; getB() are APIs out of my control and could return a null value
        if (o.getA() != null &amp;&amp; o.getB() != null) {
          return calculate(o.getA(), o.getB());
        }
      } 
  
      return Option.none();
  }
  </code></pre>
  
  <p>Calculate is simple:</p>
  
  <pre><code>private Option&lt;CalcResult&gt; calculate(Integer X, Integer Y) {
      return Option.when(X &gt; Y, () -&gt; X + Y);
  } 
  </code></pre>
  
  <p>For <code>otherMethod</code>, This was my first approach:</p>
  
  <pre><code>public Option&lt;CalcResult&gt; otherMethod(Obj o) {
      return Option.when(o.getAttr(), () -&gt; 
        For(Option.of(o.getA()), Option.of(o.getB()))
          .yield(this::calculate)
          .toOption()
          .flatMap(Function.identity())
        ).flatMap(Function.identity()); 
  }
  </code></pre>
  
  <p>But, I feel the code is not as readable as I would expect, compared to first version (double <code>flatMap</code> makes hard to understand, at first sight, why is there)</p>
  
  <p>I tried with this other, which improves the lecture:</p>
  
  <pre><code>public Option&lt;CalcResult&gt; otherMethod(Obj o) {
    return For(
        Option.when(o.getAttr(), o::getAttr()),
        Option.of(o.getA()), 
        Option.of(o.getB()))
      .yield((__, x, y) -&gt; this.calculate(x, y))
      .toOption()
      .flatMap(Function.identity()); 
  }
  </code></pre>
  
  <p>It's way more readable, but I think i'm not correctly using  For-comprehension on this case. </p>
  
  <p>What would be your recommendation on this case? am I correctly using vavr's API?</p>
  
  <p>Thanks</p>