title: Consume both "left" and "right" of Vavr Either?
body: <p>How can I consume both a &quot;left&quot; or a &quot;right&quot; of a <a href="https://www.vavr.io/" rel="nofollow noreferrer">vavr</a> <a href="https://www.javadoc.io/doc/io.vavr/vavr/latest/io/vavr/control/Either.html" rel="nofollow noreferrer">Either</a> in a functional way?</p>
  <p>I have a method that returns an <code>Either&lt;RuntimeException, String&gt;</code>. Based on this result, I need to execute a callback to our reporting library, e.g. <code>reportSuccess()</code> or <code>reportFailure()</code>. Consequently, I am looking for a nice, functional way of doing it. If an <code>Either</code> had a <code>biConsumer(Consumer&lt;? super L&gt; leftConsumer, Consumer&lt;? super R&gt; rightConsumer</code>, I could write something like:</p>
  <pre><code>Either&lt;RuntimeException, String&gt; result = // get the result from somewhere
  
  result.biConsumer(ex -&gt; {
    reportFailure();
  }, str -&gt; {
    repportSuccess();
  });
  </code></pre>
  <p>The closest workaround I have found so far is the <a href="https://www.javadoc.io/static/io.vavr/vavr/1.0.0-alpha-3/io/vavr/control/Either.html#bimap(java.util.function.Function,java.util.function.Function)" rel="nofollow noreferrer">biMap()</a> method, which would look something like</p>
  <pre><code>Either&lt;RuntimeException, String&gt; mappedResult = result.bimap(ex -&gt; {
    reportFailure();
    return ex;
  }, str -&gt; {
    reportSuccess();
    return str;
  });
  </code></pre>
  <p>Arguably, mapping functions should be used for mapping and not side effects, so even if it works I am looking for alternatives.</p>