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

lovis

10/05/2017, 8:56 AM
wasn’t there a keep/issue to support
it
inside
when
? what’s the status? i can’t find it 🤔
g

genovich

10/05/2017, 8:59 AM
It seems that tere is no need for
it
inside when
k

karelpeeters

10/05/2017, 9:00 AM
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

lovis

10/05/2017, 9:01 AM
thanks!
g

genovich

10/05/2017, 9:02 AM
Copy code
when(obj.fetchState().foo) {
    is "bar" -> println("hey")
}
Copy code
val a = obj.fetchState()
when {
    a.foo is "bar" -> println("hey")
}
k

karelpeeters

10/05/2017, 9:04 AM
Hmm they're right that the
it
stuff would make the lambda situation worse.
l

lovis

10/05/2017, 9:06 AM
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

karelpeeters

10/05/2017, 9:09 AM
is 0
doesn't work?
l

lovis

10/05/2017, 9:09 AM
no
in (0..0)
does work 🤔 looks weird tho
j

janvladimirmostert

10/05/2017, 9:11 AM
can't you just do:
Copy code
when(blah) {

			0 ->  {}

		}
l

lovis

10/05/2017, 9:11 AM
you’re right
facepalm 😅 😅 (now i feel stupid)
g

genovich

10/05/2017, 9:31 AM
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

janvladimirmostert

10/05/2017, 9:36 AM
when
is pretty flexible, you can also mix
is
in there or even do
0,1,3 -> ...