What is recommended to do when you have a case in ...
# getting-started
k
What is recommended to do when you have a case in a when where you want do to noting? Just empty {}?
m
Or just nothing? Do you mean a lambda for a NOOP (no operation)? I'd usually use empty braces indeed, e.g.
Copy code
val operation: (InputValue)->Unit = {}
t
I suggest functionally empty braces with a comment like this:
Copy code
when (a) {
  1 -> doSomething()
  2 -> { /* do nothing */ }
  3 -> throw MyException()
}
2
👍 2
r
I do similar to @Tobias Berger, though I usually put the comment outside the braces:
Copy code
when (a) {
  1 -> doSomething()
  2 -> {} // Do nothing
  3 -> throw MyException()
}
👍 3
e
I like writing
Unit
, more than {}, but it works the same