title: Kotlin nested when
body: <p>I have the next code. As you may see there are 3 <code>when</code> one inside another. Is it possible to flatten this code? I'm thinking about some wrapper but cannot get it. For now the only solution that I see is to move each when to the <code>fun</code> like <code>processFirstWhen</code> etc. Perhaps there is a cleaner solution. Any help appreciated. </p>
  
  <pre><code>when (val result = callback.invoke()) {
              is DataCompletable.Success -&gt; DomainCompletable.Success
              is DataCompletable.Error -&gt;
                  when (result.error) {
                      is DataError.Unauthorized -&gt;
                          when (tokenMixIn.refresh()) {
                              is DomainCompletable.Success -&gt; execute(
                                  currentNumberOfRetries + 1,
                                  callback
                              )
                              is DomainCompletable.Error -&gt; DomainCompletable.Error(DomainError.RefreshFailed)
                          }
                      else -&gt; DomainCompletable.Error(result.error.mapToDomain())
                  }
  </code></pre>