No-break switch

I wish there was a DRY variant of the switch construct that supported a concise syntax to filter a variable into several buckets for certain values, ranges, conditions or expressions without many case statements and without any break.

switch (foo) {
  case 3, > 7: {do numeric stuff;} 
  case /^\d+/ || /\d+$/: {do stringy stuff;}
  case undefined, NaN: {do exceptional stuff;} 
} 

See the Pattern Matching proposal: https://github.com/tc39/proposal-pattern-matching

3 Likes

Thanks, that seems to cover pretty much everything I imagined.