I started learning Dart today, and I was faced with the fact that I had no problems finding google.
How do I go about failure in a non-empty case?
My usage example: I am writing an implementation of sprintf (since the dart also does not have this), which will work, except for this failed thing. When analyzing the type of a variable, you can, for example, have "% x" compared to "% X", where the uppercase type tells the formatting that the output should be uppercase.
The semi-pseudo-code is as follows:
bool is_upper = false;
switch (getType()) {
case 'X':
is_upper = true;
case 'x':
return formatHex(is_upper);
}
Other ways I can think of would be one of the following
1
switch (getType()) {
case 'X': case 'x':
return formatHex('X' == getType());
}
2:
var type = getType();
if (type in ['x', 'X']) {
return formatHex('X' == getType());
}
Now the second option looks good, but then you have to remember that there are eleven cases, which would mean eleven if (type in []), which is more typing the text that I would like.
, dart // //$FALL-THROUGH$, ?
.