title: Call the same function with two different types from a when condition
body: <p>I was wondering if it was possible to group a call to a function that is present for two different types, without having to create two branches in the &quot;when&quot; statement.</p>
  <p>For example, in my case I have this class extensions:</p>
  <pre class="lang-kotlin prettyprint-override"><code>// File: PublisherExtensions.kt
  
  fun &lt;T&gt; Mono&lt;T&gt;.toServiceResponse(): Mono&lt;Response&lt;T&gt;&gt; =
      this.map { r -&gt; Response(true, r, null) }
          .onErrorResume { e -&gt; Mono.just(Response(false, null, Response.Error(500, e.message))) }
  
  fun &lt;T&gt; Flux&lt;T&gt;.toServiceResponse(): Mono&lt;Response&lt;List&lt;T&gt;&gt;&gt; =
      this.collectList()
          .map { r -&gt; Response(true, r, null) }
          .onErrorResume { e -&gt; Mono.just(Response(false, null, Response.Error(500, e.message))) }
  </code></pre>
  <p>And what I use with them is this statement:</p>
  <pre class="lang-kotlin prettyprint-override"><code>val body = when (val value = result.returnValue) {
      is Mono&lt;*&gt; -&gt; value.toServiceResponse()
      is Flux&lt;*&gt; -&gt; value.toServiceResponse()
      else -&gt; throw RuntimeException(&quot;The \&quot;body\&quot; should be Mono&lt;*&gt; or Flux&lt;*&gt;!&quot;)
  }
  </code></pre>
  <p>While what I would like would be this:</p>
  <pre class="lang-kotlin prettyprint-override"><code>val body = when (val value = result.returnValue) {
      is Mono&lt;*&gt;, is Flux&lt;*&gt; -&gt; value.toServiceResponse()
      else -&gt; throw RuntimeException(&quot;The \&quot;body\&quot; should be Mono&lt;*&gt; or Flux&lt;*&gt;!&quot;)
  }
  </code></pre>
  <p>The IDE gives me this error:</p>
  <blockquote>
  <p>Unresolved reference.<br />
  None of the following candidates is applicable because of receiver type mismatch:</p>
  <ul>
  <li>public fun  Flux&lt;TypeVariable(T)&gt;.toServiceResponse(): Mono&lt;Response&lt;List&lt;TypeVariable(T)&gt;&gt;&gt; defined in brc.studybuddy.backend.wrapper.util in file PublisherExtensions.kt</li>
  <li>public fun  Mono&lt;TypeVariable(T)&gt;.toServiceResponse(): Mono&lt;Response&lt;TypeVariable(T)&gt;&gt; defined in brc.studybuddy.backend.wrapper.util in file PublisherExtensions.kt</li>
  </ul>
  </blockquote>