```switch checkState { case .checking, .check...
# getting-started
u
Copy code
switch checkState {
case .checking, 
    .checked(isVerified: true):
    ProgressView()
        .controlSize(.large)
case .checked(isVerified: false):
    InlineErrorView(
        title: "...",
        message: "...",
        onRetryTapped: onRetry
    )
case .checkFailed(let errorDetails):
    InlineErrorView(
        errorDetails: errorDetails,
        onRetryTapped: onRetry
    )
}
what is the neatest way I can rewrite this in kotlin? key thing that compiler check I have consumed all the branches note that this is UI which has "positional" identity or whatever is called = I cannot have 2 branches returning
ProgressView
, as declaration UI frameworks will consider those being 2 different views
y
I would say splitting
checked
into
checkedAndVerified
and
checkedButNotVerified
would be the idiomatic way. If this is SwiftUI code I don't think Kotlin supports it though, so be aware of that
u
Do you mean to map the sealed class down at a view level again?
y
Yeah, or change the encoding of the sealed class itself if you have access to that. In general, it's more idiomatic to use types than to use booleans, and so whenever you have a data class with 1 Boolean, you likely actually want 2 objects each representing the true/false case
u
so instead of 3 cases (capturing, captured(boolean), capturingFailed) to have 4?
1
that's kinda neat, thx
although patternmatching like that would be nicer imo
y
And then you can do:
Copy code
when (checkState) {
  is Checking, is CheckedAndVerified -> ...
  is CheckedButNotVerified -> ...
  is CheckFailed -> InlineErrorView(checkState.errorDetails, onRetry) // magic of smart casts
}
👍 1
It's something that's in discussion, especially with the recent Guards KEEP proposal, but it's gonna take some time to flesh out fully
u
huh, kotlin wants guards? to me it seems they're going all in on the smart casts