wasn’t there a keep/issue to support `it` inside `...
# announcements
l
wasn’t there a keep/issue to support
it
inside
when
? what’s the status? i can’t find it 🤔
g
It seems that tere is no need for
it
inside when
k
Counterexample:
Copy code
when(obj.fetchState()) {
    it.foo is "bar" -> println("hey")
}
👍 1
I remember there being an issue/keep about this too, can't find it either right now.
l
thanks!
g
Copy code
when(obj.fetchState().foo) {
    is "bar" -> println("hey")
}
Copy code
val a = obj.fetchState()
when {
    a.foo is "bar" -> println("hey")
}
k
Hmm they're right that the
it
stuff would make the lambda situation worse.
l
Copy code
val importantNumber = obj.importantNumber()
when {
    importantNumber == 0 -> println("Oh my")
    importantNumber < 0 -> println("This")
    importantNumber > 1000 -> println("is getting")
    importantNumber > 0 -> println("repetitive")
}
another solution would probably be to allow
== 0
without a variable or something
k
is 0
doesn't work?
l
no
in (0..0)
does work 🤔 looks weird tho
j
can't you just do:
Copy code
when(blah) {

			0 ->  {}

		}
l
you’re right
facepalm 😅 😅 (now i feel stupid)
g
Copy code
val importantNumber = obj.importantNumber()
when (importantNumber) {
    0 -> println("Oh my")
    in Int.MIN_VALUE..0 -> println("This")
    in 1 until 1000 -> println("is getting")
    else -> println("repetitive")
}
j
when
is pretty flexible, you can also mix
is
in there or even do
0,1,3 -> ...