<div dir="ltr">The "after" example you posted seems to work already in Swift today. Is there something I'm missing?<div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 1, 2017 at 7:35 PM David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Sent from my iPhone</div></div><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">On Jan 1, 2017, at 19:25, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">Idea</b>: Introduce optional argument labels to tuples in switch statements</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Here's an example before:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> -> ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> switch (battery.state, battery.isCalculating) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (_, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .batteryPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">and after:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> -> ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> switch (battery.state, <b class="gmail_msg">calculating: battery.isCalculating</b>) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (_, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .</font><span style="font-family:Menlo" class="gmail_msg">batteryPower</span></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thoughts?</div></div></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">I can't think of a reason not to do that... +1</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris</div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>