<@UEJ9199JN> are you returning something out of it...
# announcements
z
@Pablo Schmid are you returning something out of it, or otherwise doing something that requires it to be exhaustive?
👆 1
p
internal sealed class RemoveProjectLibraryResult { class Removed(val library: ProjectLibraryModel) : RemoveProjectLibraryResult() class NotFound(val id: ProjectId) : RemoveProjectLibraryResult() }
that’s how I’m using it
z
show me your when block
We use the
.exhaustive
val extension
p
Let me read the post and get back if I’m wrong. Thanks Zach
z
np
a
I was surprised that
when
is not exhaustive when it’s not used as an expression. Ran into that some months ago. I was under the impression it was done for safety, and that gave me warm-fuzzies. Looks like it was only done because the compiler needs a value for the expression. I believe the equivalent in Swift is always exhaustive.
p
Thanks. That solved my issue. I was doing: when (createProjectLibrary(projectId)) { is Created -> addLibraryAsset(projectId) }
z
you could even use an
if
statement if you’re only looking for a single type
Untitled
p
of course. I was just concern because I was not getting a compilation issue( I was only handling 1 case)
z
yeah, the
.exhaustive
val from that article will let you force your when blocks to be exhaustive. Outside of that, I guess there are situations where you only want to handle a couple of potential cases, so the compiler doesn’t force you ALWAYS to handle them all
p
Very nice solutions. Thanks!