<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Was helping a friend with some code and got inspired. I decided to throw this on list to see if there's any traction. <div class=""><br class=""></div><div class=""><b class="">Idea</b>: Introduce optional argument labels to tuples in switch statements</div><div class=""><br class=""></div><div class=""><b class="">Motivation</b>: Cases can be less readable when pattern matching tuples. Semantically sugared, optional argument labels could increase readability for complex `switch` statements by incorporating roles into cases.</div><div class=""><br class=""></div><div class="">Here's an example before:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Menlo" class="">fileprivate func chargeState(for battery: BatteryService)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> -> ChargeState</font></div></div><div class=""><div class=""><font face="Menlo" class="">{</font></div></div><div class=""><div class=""><font face="Menlo" class=""> switch (battery.state, battery.isCalculating) {</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, true):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .calculating(isDischarging: false)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .charging</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, _):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .acPower</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (_, true):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .calculating(isDischarging: true)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> default:</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .batteryPower</font></div></div><div class=""><div class=""><font face="Menlo" class=""> }</font></div></div><div class=""><div class=""><font face="Menlo" class="">}</font></div></div></blockquote><div class=""><br class=""></div><div class="">and after:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div class=""><font face="Menlo" class="">fileprivate func chargeState(for battery: BatteryService)</font></div></div></div><div class=""><div class=""><font face="Menlo" class=""> -> ChargeState</font></div></div><div class=""><div class=""><font face="Menlo" class="">{</font></div></div><div class=""><div class=""><font face="Menlo" class=""> switch (battery.state, <b class="">calculating: battery.isCalculating</b>) {</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, <b class="">calculating: true</b>):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .calculating(isDischarging: false)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .charging</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (.isACPowered, _):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .acPower</font></div></div><div class=""><div class=""><font face="Menlo" class=""> case (_, <b class="">calculating: true</b>):</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .calculating(isDischarging: true)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> default:</font></div></div><div class=""><div class=""><font face="Menlo" class=""> return .</font><span style="font-family: Menlo;" class="">batteryPower</span></div></div><div class=""><div class=""><font face="Menlo" class=""> }</font></div></div><div class=""><div class=""><font face="Menlo" class="">}</font></div></div></blockquote><div class=""><br class=""></div><div class="">It's a pretty minor change, and I could see it being added to allow case statements to be more readable with a minimal change to the compiler. I also have a back-burnered proposal I intend to introduce in Phase 2 that would introduce Boolean raw value enumerations for flags.</div><div class=""><br class=""></div><div class="">Thoughts?</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div></body></html>