If I’m using `when` as an expression, can there be...
# getting-started
e
If I’m using
when
as an expression, can there be multiple statements in an arm?
d
Yes, you can use
-> { ... }
and put multiple lines and statements between the
{}
e
Thanks. How do I indicate the value of the arm? Does it just sit alone at the end? @Daniel Rampelt
d
For example
Copy code
val result = when (x) {
  condition -> {
    statement
    another statement
    last statement is the value
  }
}
✔️ 1
💯 2
e
Got it. Thanks!
👍 1
d
yep the last statement in the block is the value
a
I always find this pretty unreadable. I try to make private functions unless it really doesn't make sense
👍 1
h
I find it plenty readable enough if you format all arrows to be at the same indentation and potentially put an extra blank like after block branches
extra points if the only block branch is the final one
@Ellen Spertus last line is the return value in
if/else
and scoped functions (
let
,
run
, etc...) as well
e
@Hullaballoonatic, got it, like in Scheme sequences.