dart

Switch with connected cases

Switch with multiple connected cases with the same return value

switch (this) {
    case WeatherState.clear:
        return WeatherCondition.clear;
    case WeatherState.snow:
    case WeatherState.sleet:
    case WeatherState.hail:
        return WeatherCondition.snowy;
    case WeatherState.thunderstorm:
    case WeatherState.heavyRain:
    case WeatherState.lightRain:
    case WeatherState.showers:
        return WeatherCondition.rainy;
    case WeatherState.heavyCloud:
    case WeatherState.lightCloud:
        return WeatherCondition.cloudy;
    default:
        return WeatherCondition.unknown;
}
Was this helpful?