<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 12 Jan 2018, at 07:15, Chris Eidhof via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="">Hey SE!</div><div class=""><br class=""></div><div class="">When we have a bunch of nested structs:</div><div class=""><br class=""></div><div class=""> struct Sample {</div><div class=""> var bar: Bar</div><div class=""> }</div><div class=""> </div><div class=""> struct Bar {</div><div class=""> var show: Bool</div><div class=""> }</div><div class=""> </div><div class=""> var foo = Sample(bar: Bar(show: false))</div><div class=""><br class=""></div><div class="">It can be repetitive to toggle a deeply nested boolean:</div><div class=""><br class=""></div><div class=""> foo.bar.show = !foo.bar.show // duplication</div><div class=""><br class=""></div><div class="">I sometimes add a `toggle` extension on `Bool`</div><div class=""><br class=""></div><div class=""> extension Bool {</div><div class=""> mutating func toggle() {</div><div class=""> self = !self</div><div class=""> }</div><div class=""> }</div><div class=""><br class=""></div><div class="">This allows you to write the same code without duplication, and makes the intent clearer:</div><div class=""><br class=""></div><div class=""> foo.bar.show.toggle()</div><div class=""><br class=""></div><div class="">In other languages, I don't think the `toggle` would make as much sense, but the mutable self makes this very useful.</div><div class=""><br class=""></div><div class="">After I posted it on Twitter, it turns out I'm not the only one: <a href="https://twitter.com/PublicExtension/status/730434956376346624" class="">https://twitter.com/PublicExtension/status/730434956376346624</a></div><div class=""><br class=""></div><div class="">I would have gone straight to a proposal, but I think we can do some bikeshedding about the name of `toggle`?</div></div></div></div></blockquote><br class=""></div><div>Out of all the versions I heard, toggle is the one that makes the most sense to me.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">-- <br class=""><div class="gmail_signature">Chris Eidhof</div>
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>