Why is there not "it" in when?
# getting-started
j
Why is there not "it" in when?
s
when
isn’t a function, and it doesn’t take lambdas
d
when kinda implies the
it
.
Copy code
when(x) {
    is Thing -> {}
}
is better then
Copy code
when(x) {
   it is Thing -> {}
}
s
that second example is not valid Kotlin code
d
I know
And it would read funny if it was.
Agreed?
s
well it’s specifically because the braces attached to
when
don’t denote a lambda
and to introduce an implicit
it
would potentially be misleading
related, capturing the subject of a
when
was introduced in 1.3
Copy code
fun Request.getBody() =
        when (val response = executeRequest()) {
            is Success -> response.body
            is HttpError -> throw HttpException(response.status)
        }
d
Cool!
Kinda reminds me of Swift's
if let
s
yeah, it’s in a similar vein