<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">* Are the current stdlib names for optional&nbsp;<font face="Courier" class="">map</font>&nbsp;and&nbsp;<font face="Courier" class="">flatMap</font>&nbsp;misleading?&nbsp;</div></div></blockquote></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">It depends on the interpretation. The one that I came across in “Functional Swift” describes map and flatMap for container types that are not necessarily collections (Result is another container type that immediately comes to mind which is not a collection). Since these concepts are not specific to Swift, I think that it’s very important that Swift uses the names that are already established for these concepts.<br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">* Are the current stdlib functions for optional closure application appropriate and sufficient?</div></div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">I’d love to see what is called “ifPresent” in the subject of the thread. But I think that it should be called “apply” (<a href="https://en.wikipedia.org/wiki/Apply" class="">https://en.wikipedia.org/wiki/Apply</a>)</div></div></div></div></div></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 20, 2016, at 1:52 PM, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Questions being raised in this discussion:</div><div class=""><br class=""></div><div class="">* Are the current stdlib names for optional <font face="Courier" class="">map</font> and <font face="Courier" class="">flatMap</font> misleading?&nbsp;</div><div class="">* Are the current stdlib functions for optional closure application appropriate and sufficient?</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier" class="">&nbsp; &nbsp; @warn_unused_result</font></div><div class=""><font face="Courier" class="">&nbsp; &nbsp; public func map&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U) rethrows -&gt; U?</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">&nbsp; &nbsp; @warn_unused_result</font></div><div class=""><font face="Courier" class="">&nbsp; &nbsp; public func flatMap&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U?) rethrows -&gt; U?</font></div></div><div class=""><br class=""></div><div class="">Assume there could be up to three stdlib functions just for applying closures to .some-case&nbsp;</div><div class="">optionals. Would they look like this?</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">public func f1&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U) rethrows -&gt; U?</font></div><div class=""><div class=""><font face="Courier" class="">public func f2&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U!) rethrows -&gt; U!</font></div></div><div class=""><div class=""><font face="Courier" class="">public func f3&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U) rethrows -&gt; Void</font></div></div><div class=""><br class=""></div><div class="">Right now f2/flatMap returns U?, not U or U!, and won't throw if nil, right? Should it</div><div class="">stay that way or change to something that throws and returns a guaranteed value?</div><div class="">Or maybe the current "f2" model (flatMap) &nbsp;be discarded and replaced by an&nbsp;</div><div class="">"<font face="Courier" class="">ifPresent</font>"-like Void call?</div><div class=""><br class=""></div><div class="">And regardless of which functions are included, what would the appropriate&nbsp;</div><div class="">names for each function style be?</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 20, 2016, at 11:22 AM, Andrey Tarantsov &lt;<a href="mailto:andrey@tarantsov.com" class="">andrey@tarantsov.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">No. &nbsp;My argument is that map on collections and on optionals are two<br class="">completely different things. &nbsp;They unify on a level that does not<br class="">exist in Swift (higher-kinded types).<br class=""></blockquote><br class="">+1000.<br class=""><br class="">Optional.map is already highly unfortunate. It makes optional arrays especially painful to deal with, but even in general, you can no longer glance at the code and see which parts are dealing with many items and which parts are dealing with single items.<br class=""><br class="">I would definitely support renaming Optional.{map,flatMap}.<br class=""><br class="">A.<br class=""><br class=""></div></div></blockquote></div><br class=""></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>