title: Nested Mono in Either
body: <p>I have a method to register a user:</p>
  <pre><code>public Mono&lt;Either&lt;AppError, UserDTO&gt; &gt; registerUser(RegisterUserDTO dto) {
  Mono&lt;Either&lt;AppError, Mono&lt;UserDTO&gt; &gt; &gt; result = userFactory
          .create(dto.username(), dto.password(), UserRole.COMMON)
          .map(it -&gt; it
                  .map(user -&gt; reactiveUserRepository
                          .add(user)
                          .map(User::toDTO)
                  )
          );
     return result;
  }
  </code></pre>
  <p>Create method from UserFactory returns Mono&lt;Either&lt;AppError, User&gt; &gt; and add method from ReactiveUserRepository returns Mono&lt; User &gt;. Of course, it doesn't compile, because i need Mono&lt;Either&lt;AppError, UserDTO&gt; &gt; instead of Mono&lt;Either&lt;AppError, Mono&lt; UserDTO &gt; &gt; &gt;. How i can do that?</p>
  <p>Update:
  It's a solution from other forum:</p>
  <pre><code>public Mono&lt;Either&lt;AppError, UserDTO&gt; &gt; registerUser(RegisterUserDTO dto) {
  return userFactory
          .create(dto.username(), dto.password(), UserRole.COMMON)
          .flatMap(it -&gt; it
                  .map(user -&gt; reactiveUserRepository
                          .add(user)
                          .map(u -&gt; Either.&lt;AppError, UserDTO&gt;right(u.toDTO() ) )
                  )
                  .mapLeft(error -&gt; Mono.just(Either.&lt;AppError, UserDTO&gt;left(error) ) )
                  .getOrElseGet(error -&gt; error)
          );
  }
  </code></pre>
  <p>Anybody has better idea or it's best one? (It looks horrible, i know)</p>