Skip to content

Instantly share code, notes, and snippets.

@GuilhE
Last active June 28, 2021 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuilhE/7763fa4155f5785e405a15f81242385c to your computer and use it in GitHub Desktop.
Save GuilhE/7763fa4155f5785e405a15f81242385c to your computer and use it in GitHub Desktop.
Medium article - KMM
suspend fun createReservation(): ReservationResult<Unit> {
return when (val response = api.createReservation(...)) {
is ApiResult.Success -> ReservationResult.Success
is ApiResult.Error -> ReservationResult.Error(response.exception)
}
}
sealed class ReservationResult<out T : Any> {
object Success : ReservationResult<Unit>()
data class Error(val exception: Throwable) : ReservationResult<Nothing>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment