Hacker News new | ask | show | jobs
by okbake 3397 days ago
You can do something similiar in rust. 'if' is an expression, so it can appear on the right hand side of an assignment.

  let x = if number > 2 { "yes" } else { "no" };
It's not quite the same, and I'm not sure what the failure case would be if the 'else' statement was ommitted, but it comes close.

After experimenting with Rust and Elixir I've really come to like the 'everything is an expression' approach. That and pattern matching can make some things really expressive.

1 comments

Ah yes... ternaries. Actually, it's two things I miss :)