<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=""><blockquote type="cite" class="">On Jan 11, 2018, at 7:55 PM, Kenny Leung via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I’m trying to write a utility method that is kind of the opposite of “x ?? y”, which means “x != nil ? &nbsp;x : y”. I want “x != nil ? f(x) : nil”</span></div></blockquote><div><br class=""></div><div>A good name for this method might be ‘map’ ;-)</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> This is not difficult to write, but if you have "f(x)-&gt;z" and "g(x)-&gt;z?",</span></div></blockquote></div><br class=""><div class="">And a good name for this one might be ‘flatMap’. ;-)</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">I seem to need two versions of the function in order to handle it. Is there any way to do this with only one function?</blockquote><br class=""></div><div class="">I don’t think so; if this were possible, there probably wouldn’t be the two methods to do this in the standard library.</div><div class=""><br class=""></div><div class="">Charles</div><div class=""><br class=""></div></body></html>