I'm sure there's a reason, so I figured I'd ask why there isn't a
ternary expression?
It seems like ternary would help with the functional paradigm of
Elixir.
I realize one can use the `if...` as a construct, but it just isn't very readable (imho of course).
Consider:
vs:
Invariably when I come upon a use case for a single-line if, I end up never liking its readability. So instead of the above, I end up with:
While this works, it's also not great, because I try to avoid assignments wherever possible (being a functional language and all).
Anyway, just a question more than anything. Thanks!
-Brandon
A few other things to address suggestions I know may come:
1. "It's too cryptic" — I just need to point to the `&(&1)` type shortcut to show precedence for smaller syntax sugar in elixir.
2. Just make a `ternary()` function — but I don't think it really helps any with the visual readability, and in fact is probably LESS so since it's a less known function/name in the general programming world, where ternary ?: is pretty ubiquitous.
3. use pipes in the above last example — not what I want, because
that requires re-ordering the function's arguments. That's a
bizarre requirement just because we can't handle ternary's.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/112d8d35-c65e-4d8d-a221-5707c211f26b%40cold.org.
avariable = true ? 42 : 43
#include <iostream>
int main() {
int value = true ? 42 : 43; // value is 43
std::cout << "Value is: " << value << std::endl;
return 0;
}
--