Since the ternary operator was one of my favorite ways of DRYing up Java and Ruby, I find myself missing it in Elixir. Here are the two alternatives I've seen so far:
my_string = condition ? "value 1" : "value 2" <-- In Ruby
my_string = if condition, do: "value 1", else: "value 2" <-- option #1 in Elixir
my_string = condition && "value 1" || "value 2" <-- option #2 in Elixir
Is this correct? Are there better or other ways to get the same job done?
I see that someone else had suggested option #2 as an alternative in Ruby, here:
As far as I can tell, the two options should be the same unless "value 1" is meant to be false or nil.
Posting this here for discussion or for other noobs to stumble on when looking forlornly for the ?: operator.
With kind regards,
Daniel