https://kotlinlang.org logo
#announcements
Title
# announcements
z

zachtib

09/12/2019, 7:41 PM
@Pablo Schmid are you returning something out of it, or otherwise doing something that requires it to be exhaustive?
👆 1
p

Pablo Schmid

09/12/2019, 7:42 PM
internal sealed class RemoveProjectLibraryResult { class Removed(val library: ProjectLibraryModel) : RemoveProjectLibraryResult() class NotFound(val id: ProjectId) : RemoveProjectLibraryResult() }
that’s how I’m using it
z

zachtib

09/12/2019, 7:42 PM
show me your when block
We use the
.exhaustive
val extension
p

Pablo Schmid

09/12/2019, 7:44 PM
Let me read the post and get back if I’m wrong. Thanks Zach
z

zachtib

09/12/2019, 7:45 PM
np
a

andym

09/12/2019, 7:48 PM
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

Pablo Schmid

09/12/2019, 7:48 PM
Thanks. That solved my issue. I was doing: when (createProjectLibrary(projectId)) { is Created -> addLibraryAsset(projectId) }
z

zachtib

09/12/2019, 7:49 PM
you could even use an
if
statement if you’re only looking for a single type
Untitled
p

Pablo Schmid

09/12/2019, 7:50 PM
of course. I was just concern because I was not getting a compilation issue( I was only handling 1 case)
z

zachtib

09/12/2019, 7:51 PM
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

Pablo Schmid

09/12/2019, 9:00 PM
Very nice solutions. Thanks!