<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 4, 2016, at 1:41 PM, Tim Vermeulen via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">You want `flatMap`:<br class=""><br class="">let dobString = dob.flatMap(serverDateFormatter.stringFromDate)<br class=""><br class="">Or if you want `dobString` to be non-optional:<br class=""><br class="">let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “"<br class=""></div></div></blockquote><div><br class=""></div>You can just use map here too, right?</div><div><br class=""></div><div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> dobString2: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">dob</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">serverDateFormatter</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">string</span><span style="font-variant-ligatures: no-common-ligatures" class="">) ?? </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">""</span></div></div><div><br class=""></div><div>I was a little surprised that this didn't need the rest of the selector signature but that's because parameter stripping and type matching, isn't it?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">Currently I do stuff like this:<br class=""><br class="">letdobString:String<br class="">ifletdob = dob {<br class="">dobString =serverDateFormatter.stringFromDate(dob)<br class="">}<br class="">else{<br class="">dobString =""<br class="">}<br class=""><br class="">Is there a better, more idiomatic, way to do this sort of thing?<br class=""><br class=""><br class=""><br class=""><br class=""></blockquote>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></body></html>