title: How to Use "zipWhen" With Conditions?
body: <p>Hello I would like to know how to use the "zipwhen" function of the reactor project since it is not clear in the documentation.</p>
  
  <p>My problem is the following I make a series of calls to Rest / Web services the issue is that as I have it now I always call all the services but I would like to parameterize so as not always to call all of them if it does not depend on the needs using zipwhen.</p>
  
  <p>I don´t really know if is possible using zipwhen.</p>
  
  <p>Something like :</p>
  
  <p>I have a class service in which I make the calls to the different web services (since it is an example it is always the same but in fact it will be to n different web services)</p>
  
  <pre><code>@Service
  public class FuenteRiesgoService {
  
      @Autowired
      SmartBearWsClient smartBearWsClient;
  
      public Mono&lt;GetCurrentTimeResponse&gt; fuenteWS1() {
  
          return Mono.fromCallable(() -&gt; {
              Random rn = new Random();
              System.out.println("Llamando a fuente WS1 ..... on " + Thread.currentThread().getName());
              Thread.sleep(rn.nextInt(50 - 1 + 1) + 1 * 10000);
              GetCurrentTimeResponse getCurrentTimeResponse = smartBearWsClient.getCurrentTime(new GetCurrentTime());
              System.out.println("Respuesta fuente WS1 " + getCurrentTimeResponse.getGetCurrentTimeResult() + " on "
                      + Thread.currentThread().getName());
              return getCurrentTimeResponse;
          }).subscribeOn(Schedulers.parallel());
  
      }
  
      public Mono&lt;GetCurrentTimeResponse&gt; fuenteWS2(boolean call) {
  
          return Mono.fromCallable(() -&gt; {
              Random rn = new Random();
              System.out.println("Llamando a fuente WS2 ..... on " + Thread.currentThread().getName());
              Thread.sleep(rn.nextInt(50 - 1 + 1) + 1 * 10000);
              GetCurrentTimeResponse getCurrentTimeResponse = smartBearWsClient.getCurrentTime(new GetCurrentTime());
              System.out.println("Respuesta fuente WS2 " + getCurrentTimeResponse.getGetCurrentTimeResult() + " on "
                      + Thread.currentThread().getName());
              return getCurrentTimeResponse;
          }).subscribeOn(Schedulers.parallel());
  
      }
  
  public Mono&lt;GetCurrentTimeResponse&gt; fuenteWS3() {
  
      return Mono.fromCallable(() -&gt; {
          Random rn = new Random();
          System.out.println("Llamando a fuente WS3 ..... on " + Thread.currentThread().getName());
          Thread.sleep(rn.nextInt(50 - 1 + 1) + 1 * 10000);
          GetCurrentTimeResponse getCurrentTimeResponse = smartBearWsClient.getCurrentTime(new GetCurrentTime());
          System.out.println("Respuesta fuente WS3 " + getCurrentTimeResponse.getGetCurrentTimeResult() + " on "
                  + Thread.currentThread().getName());
          return getCurrentTimeResponse;
      }).subscribeOn(Schedulers.parallel());
  
  }
  
  public Mono&lt;GetCurrentTimeResponse&gt; fuenteWS4() {
  
      return Mono.fromCallable(() -&gt; {
          Random rn = new Random();
          System.out.println("Llamando a fuente WS4 ..... on " + Thread.currentThread().getName());
          Thread.sleep(rn.nextInt(50 - 1 + 1) + 1 * 10000);
          GetCurrentTimeResponse getCurrentTimeResponse = smartBearWsClient.getCurrentTime(new GetCurrentTime());
          System.out.println("Respuesta fuente WS4 " + getCurrentTimeResponse.getGetCurrentTimeResult() + " on "
                  + Thread.currentThread().getName());
          return getCurrentTimeResponse;
      }).subscribeOn(Schedulers.parallel());
  
  }
  
  }
  </code></pre>
  
  <p>With this return what it does is to call the 4 web services always</p>
  
  <pre><code>return fuenteRiesgoService.fuenteWS1()
      .zipWith(fuenteRiesgoService.fuenteWS2(), (a, b) -&gt; {
      return " - WS1 : " + a.getGetCurrentTimeResult().toString() + " - WS2 : "
                  + b.getGetCurrentTimeResult().toString();
  }).zipWith(fuenteRiesgoService.fuenteWS3(), (a, b) -&gt; {
      return a + " - WS3 : " + b.getGetCurrentTimeResult().toString();
  }).zipWith(fuenteRiesgoService.fuenteWS4(), (a, b) -&gt; {
      System.out.println("Fuentes obtenidas " + a + " - WS4 : " + b.getGetCurrentTimeResult().toString()
                  + " on " + Thread.currentThread().getName());
      return a + " - WS4 : " + b.getGetCurrentTimeResult().toString();
  });
  </code></pre>
  
  <p>But what I want to do is to be able to call oneself and others not through parameters with zipwhen.</p>
  
  <p>For example, call ws2 and ws4 but not ws3, so it does not do anything with the ws3</p>
  
  <pre><code>boolean callws2 = true;
  boolean callws3 = false;
  boolean callws4 = true;
  
  return fuenteRiesgoService.fuenteWS1()
      .zipWhen(if(callws2 = true) -&gt; fuenteRiesgoService.fuenteWS2(), (a, b) -&gt; {
      return " - WS1 : " + a.getGetCurrentTimeResult().toString() + " - WS2 : "
                  + b.getGetCurrentTimeResult().toString();
  }).zipWhen(if(callws3 = true) -&gt; fuenteRiesgoService.fuenteWS3(), (a, b) -&gt; {
      return a + " - WS3 : " + b.getGetCurrentTimeResult().toString();
  }).zipWhen(if(callws4 = true) -&gt; fuenteRiesgoService.fuenteWS4(), (a, b) -&gt; {
      System.out.println("Fuentes obtenidas " + a + " - WS4 : " + b.getGetCurrentTimeResult().toString()
                  + " on " + Thread.currentThread().getName());
      return a + " - WS4 : " + b.getGetCurrentTimeResult().toString();
  });
  </code></pre>