title: Handle api response using sealed class in rxjava
body: <blockquote>
  <p>I want to handle api response using sealed class</p>
  </blockquote>
  <pre><code>sealed class Result&lt;out T&gt; {
  
      data class Success&lt;out T&gt;(val value: T) : Result&lt;T&gt;()
      data class Failure&lt;out T&gt;(val throwable: Throwable) : Result&lt;T&gt;()
  }
  </code></pre>
  <p>My api is working properly for</p>
  <pre><code>@POST(&quot;/api/doctor_app/UpdateProfile&quot;)
  fun UpdateProfile(@Body request: Doctor): Single&lt;GenericResponse&gt;
  </code></pre>
  <p>and when I updated my api to</p>
  <pre><code>@POST(&quot;/api/doctor_app/UpdateProfile&quot;)
  fun UpdateProfile(@Body request: Doctor): Single&lt;Result&lt;GenericResponse&gt;&gt;
  </code></pre>
  <p><strong>Failed to invoke private com.utils.Result() with no args</strong></p>
  <p>How can I achieve response like</p>
  <pre><code>configService.UpdateProfile(doctor)
              .subscribeOnIO()
              .map {
                  when(it){
                      is Result.Success -&gt; Result.Success(it.value)
                      is Result.Failure -&gt; Result.Failure&lt;GenericResponse&gt;(it.throwable)
                  }
              }
  </code></pre>
  <p>where <strong>subscribeOnIO</strong></p>
  <pre><code>fun &lt;T&gt; Single&lt;T&gt;.subscribeOnIO(): Single&lt;T&gt; {
      return this.subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
  }
  </code></pre>