Here's a good explanation of map and some other functional idioms in Swift:<br><a href="http://www.mokacoding.com/blog/functor-applicative-monads-in-pictures/">http://www.mokacoding.com/blog/functor-applicative-monads-in-pictures/</a><br><br>I hope it adequately explains to you why Optional, like Array, has a method called map. Unwrapping and rewrapping is inherent to the meaning of the term "map." Likewise, this article explains flatMap and what it does. These are terms of art that have specific meanings. The idea of renaming them was considered during Swift 3 evolution and the decision was made to keep them as they are.<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 5, 2016 at 23:35 Jay Zhao via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">We can make the code condense when the optional is used <b class="gmail_msg">as a parameter</b>:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><span class="m_-8980553918041117241Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>/// Long version</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">if</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> doubleValue = json</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">[</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"taken_at"</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">]</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">double</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">createTime</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">Date</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(timeIntervalSince1970:doubleValue)</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> }</span></div><p style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><br class="m_-8980553918041117241webkit-block-placeholder gmail_msg"></p><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">/// Shourt version</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">createTime</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = json</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">[</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"taken_at"</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">]</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">double</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">mapUnwrapped</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">{ </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">Date</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(timeIntervalSince1970:$0) }</span></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 6 Dec 2016, at 13:18, David Sweeris <<a href="mailto:davesweeris@mac.com" class="gmail_msg" target="_blank">davesweeris@mac.com</a>> wrote:</div><br class="m_-8980553918041117241Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Dec 5, 2016, at 9:17 PM, David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-8980553918041117241Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Dec 5, 2016, at 8:54 PM, Jay Zhao <<a href="mailto:zhaojianyin@icloud.com" class="gmail_msg" target="_blank">zhaojianyin@icloud.com</a>> wrote:</div><br class="m_-8980553918041117241Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">What about <span style="font-size:14px" class="gmail_msg"><font color="#38571a" class="gmail_msg">mapUnwrapped ?</font></span></div></div></div></blockquote><br class="gmail_msg"></div><div class="gmail_msg">If the name is anything other than “map”, you already have to think of the “special” word. At that point, why not just unwrap it manually?</div><div class="gmail_msg"><span style="font-family:Menlo;font-size:13px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="gmail_msg">_</span><span style="font-family:Menlo;font-size:13px;font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array2?</span><span style="font-family:Menlo;font-size:13px;font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-family:Menlo;font-size:13px;font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="gmail_msg">count</span></div><div class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">vs</span></div><div class="gmail_msg"><span style="font-family:Menlo;font-size:13px;font-variant-ligatures:no-common-ligatures" class="gmail_msg"><span style="color:rgb(186,45,162);font-variant-ligatures:no-common-ligatures" class="gmail_msg">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array2?</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.map {$0.</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><font color="#703daa" class="gmail_msg">count</font>}</span></span></div></div></div></blockquote>Oops, there shouldn’t be a “?" on the last line</div></div></div></blockquote></div><br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>