title: How to place a conditional check inside springboot project reactor Mono stream (written in Kotlin)?
body: <p>Pretty new to project reactor here, I am struggling to put a conditional check inside my Mono stream. This part of my application is receiving an object from Kafka. Let's say the object is like this.</p>
  
  <pre><code>data class SomeEvent(val id: String, val type: String)
  </code></pre>
  
  <p>I have a function that handles this object like this.</p>
  
  <pre><code>fun process(someEvent: SomeEvent): Mono&lt;String&gt; {
    val id = someEvent.id
    val checkCondition = someEvent.type == "thisType"
  
    return repoOne.getItem(id)
      .map {item -&gt;
        // WHAT DO I DO HERE TO PUT A CONDITIONAL CHECK
        createEntryForItem(item)
      }
      .flatMap {entry -&gt;
        apiService.sendEntry(entry)
      }
      .flatMap {
        it.bodyToMono(String::class.java)
      }
      .flatMap {body -&gt;
        Mono.just(body)
      }
  }
  </code></pre>
  
  <p>So, what I want to do is check whether <code>checkCondition</code> is <code>true</code> and if it is, I want to call a function <code>repoTwo.getDetails(id)</code> that returns a <code>Mono&lt;Details&gt;</code>.</p>
  
  <p><code>createEntryForItem</code> returns an object of type <code>Entry</code></p>
  
  <p><code>apiService.sendEntry(entry)</code> returns a <code>Mono&lt;ClientResponse&gt;</code></p>
  
  <p>It'd be something like this (in my mind).</p>
  
  <pre><code>fun process(someEvent: SomeEvent): Mono&lt;String&gt; {
    val id = someEvent.id
    val checkCondition = someEvent.type == "thisType"
  
    return repoOne.getItem(id)
      .map {item -&gt;
        if (checkCondition) {
          repoTwo.getDetails(id).map {details -&gt;
            createEntryForItem(item, details)
          }
        } else {
          createEntryForItem(item)
        }          
      }
      .flatMap {entry -&gt;
        apiService.sendEntry(entry)
      }
      .flatMap {
        it.bodyToMono(String::class.java)
      }
      .flatMap {body -&gt;
        Mono.just(body)
      }
  }
  </code></pre>
  
  <p>But, obviously, this does not work because the expression inside the <code>if statement</code> is cast to <code>Any</code>.</p>
  
  <p>How should I write it to achieve what I want to achieve?</p>
  
  <p>UPDATED: The location of where I like to have the conditional check.</p>