title: The Logic behind These Two Functions - Java
body: <h1>Introduction</h1>
  <p>Let's talk about isomorphism here. I have a class that implementing isomoprhism and it is called <strong>ISO</strong> Class. I have this class from the solution of kata in codewars. Reference of isomorphism can be seen <a href="https://en.wikipedia.org/wiki/Isomorphism" rel="nofollow noreferrer">here</a>. This class have many functions to represent the characteristics of isomoprhism. At first, I can understand the logic behind some functions of the class. But, at some point, I got stuck at these two functions. This give me two problems and those problems can be seen in sections below.</p>
  <h1>Problem 1</h1>
  <pre><code>static &lt;A, B&gt; ISO&lt;A, B&gt; isoUnOptional(final ISO&lt;Optional&lt;A&gt;, Optional&lt;B&gt;&gt; iso) {
      return iso(
        a -&gt; iso.fw(Optional.of(a))
              .orElseGet(() -&gt; iso.fw(Optional.empty()).get()),
        b -&gt; iso.bw(Optional.of(b))
              .orElseGet(() -&gt; iso.bw(Optional.empty()).get()));
    }
  </code></pre>
  <h1>Problem 2</h1>
  <pre><code>static ISO&lt;Either&lt;Stream&lt;Unit&gt;, Unit&gt;, Either&lt;Stream&lt;Unit&gt;, Void&gt;&gt; isoEU() {
      return iso(
        l -&gt; l.pm(
          ll -&gt; Either.left(Stream.concat(Stream.of(Unit.INSTANCE), ll)),
          r -&gt; Either.left(Stream.empty())),
        r -&gt; r.pm(
          l -&gt; { 
            List&lt;Unit&gt; lu = l.collect(Collectors.toList());
            return lu.isEmpty() ? 
                Either.right(Unit.INSTANCE) :
                Either.left(Stream.generate(() -&gt; 
                    Unit.INSTANCE).limit(lu.size() - 1)); 
          },
          Void::absurd));
  }
  </code></pre>
  <p>Each function give me a problem. The problem is I don't understand the inner working of the return statement. I know about the <a href="https://stackoverflow.com/questions/16859992/java-lambda-expressions">syntax</a>, but I don't know about the logic of it. Could someone explain to me about the logic of these two problems?</p>
  <h2>Note</h2>
  <ol>
  <li>The term of logic in here is same as the term of inner working.</li>
  <li>The full structure of the code can be seen below.</li>
  </ol>
  <h2>Complete Code</h2>
  <p>The full code: <a href="https://pastebin.com/tTdnBDD7" rel="nofollow noreferrer">Full Code of ISO Class</a></p>