title: How do I implement methods using Method Reference inside a map or flatMap
body: <p>I was reading <a href="https://stackoverflow.com/a/54127397/3672700">this</a> so I could understand better how to deal with asynchronous requests, and even though I understand what he is doing here:</p>
  <pre><code>.map(processor::responseToDatabaseEntity) // Create a persistable entity from the response
  .map(priceRepository::save)               // Save the entity to the database
  </code></pre>
  <p>I have no idea how these two methods would be implemented. Assuming this very simple code:</p>
  <pre><code>public Mono&lt;Response&gt; postMethod(String id, Person json) {
          return webClient.post().uri(id).body(Mono.just(json), Person.class).retrieve().bodyToMono(Response.class);
  }
  </code></pre>
  <p>And the Response Class, something like:</p>
  <pre><code>public class Response implements Serializable{
      
      private static final long serialVersionUID = -4101206629695985431L;
      
      public String statusCode;
      public Date date;
      public PersonInfo data;
  </code></pre>
  <p>I assume the <code>responseToDatabaseEntity</code> method would be some sort of transformation from the Response to PersonInfoDTO to the database, and the <code>save</code> would insert into it. But how could I implement something like that using Method Reference(::) that would work inside the <code>.map()</code> so I can subscribe() after is what I don't understand.</p>
  <p>EDIT:
  Adding the progress I had but adapting more or less to the example I gave with Person class:</p>
  <pre><code>public Mono&lt;Object&gt; postPerson(String id, Person json) {
          return webClient.post().uri(id).body(Mono.just(json), Person.class).retrieve().bodyToMono(Response.class).map( c -&gt; {
              List&lt;PersonDTO&gt; list = new ArrayList&lt;PersonDTO&gt;();
              c.data.getRoles().forEach((r) -&gt; {
                  PersonDTO dto = new PersonDTO(c.data.getOof(), &quot;something&quot;, c.data.getFoo(), r);
                  list.add(dto);
              });
              return list;        
          }).map(personController::savePerson).subscribe(); //what I wanted to do
      }
  </code></pre>
  <p>If I do this:</p>
  <pre><code>    });
      return list;        
  }).map(l -&gt; {
          l.
      });
  </code></pre>
  <p><code>l</code> contains a list of PersonDTO, and if I do this:</p>
  <pre><code>  .map(l -&gt; {
          l.forEach( f -&gt; {
              f.
          });
      });
  </code></pre>
  <p><code>f</code> contains a Person.</p>
  <p>How should I implement the method to send the entire list to insert in the method or send one person by person to <code>save</code>. I can't use a static method like <code>PersonController::savePerson</code> because:</p>
  <pre><code>@RestController
  public class PersonController {
  
      private final Logger LOG = LoggerFactory.getLogger(getClass());
  
      @Autowired
      private final PersonInterface personRepository;
  
      public PersonController(PersonInterface personRepository) {
          this.personRepository = personRepository;
      }
  </code></pre>
  <p><code>personRepository</code> cannot be <code>static</code>.</p>
  <p>EDIT2: Have also tried this, does not work:</p>
  <pre><code>public List&lt;PersonDTO&gt; savePerson(List&lt;PersonDTO&gt; list) {
          list.forEach(dto -&gt; {
              personRepository.save(dto);
          });
          return list;
  }
  </code></pre>