<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">It reads better and feels more natural. In my mind, it’s similar to the difference between <div class=""><br class=""></div><div class="">["1", "2", "3"].flatMap { Double($0) }</div><div class=""><br class=""></div><div class="">and</div><div class=""><br class=""></div><div class="">["1", "2", "3"].flatMap(Double.init)</div><div class=""><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Jun 9, 2017, at 16:06, Max Moiseev 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 class="">Sorry. I might be missing something. Why is this better than:<br class=""><br class="">let allEmployees = Set(managers.flatMap { $0.directReports }<br class=""><br class="">?<br class=""><br class=""><blockquote type="cite" class="">On Jun 7, 2017, at 10:35 AM, Adam Sharp via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">The new smart key path feature is really lovely, and feels like a great addition to Swift.<br class=""><br class="">It seems like it might be straightforward to add overloads of `map` and `flatMap` to the standard library to make use of the new functionality:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let managers = flatOrganisation.managers<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let allEmployees = Set(managers.flatMap(\.directReports))<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let employeeNames = Set(allEmployees.map(\.name))<br class=""><br class="">This feels like a really natural way of working with key paths in a functional style. It makes a lot of sense for collections, and possibly for Optional too (although as far as I can see optional chaining is more or less equivalent, and with more compact syntax).<br class=""><br class="">I’m hoping that this might be low-hanging fruit that could be considered for the Swift 4 release. I’d be happy to have a go at writing a proposal if there’s interest!<br class=""><br class="">–Adam<br class=""><br class="">_______________________________________________<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=""></blockquote><br class="">_______________________________________________<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></div></blockquote></div><br class=""></div></div></body></html>