<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><br><div>On Jan 11, 2018, at 22:15, Chris Eidhof via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div><div>Hey SE!</div><div><br></div><div>When we have a bunch of nested structs:</div><div><br></div><div> struct Sample {</div><div> var bar: Bar</div><div> }</div><div> </div><div> struct Bar {</div><div> var show: Bool</div><div> }</div><div> </div><div> var foo = Sample(bar: Bar(show: false))</div><div><br></div><div>It can be repetitive to toggle a deeply nested boolean:</div><div><br></div><div> foo.bar.show = !foo.bar.show // duplication</div><div><br></div><div>I sometimes add a `toggle` extension on `Bool`</div><div><br></div><div> extension Bool {</div><div> mutating func toggle() {</div><div> self = !self</div><div> }</div><div> }</div><div><br></div><div>This allows you to write the same code without duplication, and makes the intent clearer:</div><div><br></div><div> foo.bar.show.toggle()</div><div><br></div><div>In other languages, I don't think the `toggle` would make as much sense, but the mutable self makes this very useful.</div><div><br></div><div>After I posted it on Twitter, it turns out I'm not the only one: <a href="https://twitter.com/PublicExtension/status/730434956376346624">https://twitter.com/PublicExtension/status/730434956376346624</a></div><div><br></div><div>I would have gone straight to a proposal, but I think we can do some bikeshedding about the name of `toggle`?</div></div></div></blockquote><br><div>“Toggle” works for me, if we go this route.</div><div><br></div><div>I have a question about the idea, though... Why limit this to Bools? In principle, as long as there aren’t any associated values involved, shouldn’t we be able to iterate through any exhaustive enum type? Bools are an obvious example of a case where “x.nextCase” is useful, but should we consider whether we ought to instead give this functionality to all enums that don’t have associated values?</div><div><br></div><div>- Dave Sweeris</div></body></html>