<div style="white-space:pre-wrap">Jay, I fail to see the point you are trying to make.  Can you clarify why we need a new map method for an optional array of elements?</div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Dec 6, 2016 at 9:46 PM Jay Zhao via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" 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"><div class="gmail_msg"><font size="2" class="gmail_msg">It applies in theory to think Optional as a collect of one and for that reason map is a perfect name.</font></div><div class="gmail_msg"><font size="2" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font size="2" class="gmail_msg">But in practice, we often use the same variable name for <b class="gmail_msg">array</b> and <b class="gmail_msg">array?</b> .  So when you see :</font></div><div class="gmail_msg"><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-family:Helvetica;font-size:small" class="gmail_msg"><span class="m_918642921984995860m_-484177411408662380Apple-tab-span gmail_msg" style="white-space:pre-wrap">                </span>cars.</span><b style="font-family:Helvetica" class="gmail_msg">map</b><span style="font-family:Helvetica;font-size:small" class="gmail_msg">({...$0...})  </span></div></div><div class="gmail_msg"><font size="2" class="gmail_msg">You can not tell which map and even worse which $0 it is.</font></div><div class="gmail_msg"><font size="2" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font size="2" class="gmail_msg">According to Swift API Design Guidelines <b class="gmail_msg">#1</b>, <strong style="box-sizing:border-box;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif" class="gmail_msg">Clarity at the point of use</strong>. </font></div><div class="gmail_msg"><span style="font-size:small" class="gmail_msg">And to combine theory and practice, I propose </span><b class="gmail_msg">mapUnwrapped</b><span style="font-size:small" class="gmail_msg"> to remove the confusion.</span></div><div class="gmail_msg"><font size="2" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font size="2" class="gmail_msg">Actually this is what’s been adopted in my company:</font></div></div><div class="gmail_msg"><div 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="gmail_msg"></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">public</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="gmail_msg">Optional</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)" class="gmail_msg"> {</span></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;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">/// Pass the `Optional` into the closure that returns `Non-Optional`</span></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;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">public</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">func</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> mapUnwrapped&lt;U&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> transform: (</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">Wrapped</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">throws</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">U</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">rethrows</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">U</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">? {</span></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;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">return</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">try</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">map</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(transform)</span></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">    }</span></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div></div><div style="margin:0px;line-height:normal;font-family:Menlo" class="gmail_msg"><br class="gmail_msg"></div><div style="margin:0px;line-height:normal;font-family:Menlo" class="gmail_msg">To summary my idea:</div><div style="margin:0px;line-height:normal;font-family:Menlo" class="gmail_msg">This is the situation where usability &gt; design purity for a language(a tool).</div></blockquote></blockquote></div><div style="word-wrap:break-word" class="gmail_msg"><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 7 Dec 2016, at 08:05, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" class="gmail_msg" target="_blank">devteam.codafi@gmail.com</a>&gt; wrote:</div><br class="m_918642921984995860m_-484177411408662380Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="auto" class="gmail_msg"><div class="gmail_msg">If you think of Optional as a zero-or-one element collection there&#39;s really no reason this operation should be named any differently.  It still lifts a function over values to one over Optionals.  It still extracts the contents of the structure and applies the function (propagating failure if necessary).  The operation is no different from the one required of a plain Sequence conformance, why should it have a new name if it is not a new operation? </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">~Robert Widmann</div></div><div class="gmail_msg"><br class="gmail_msg">2016/12/05 22:46、Jay Zhao via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; のメッセージ:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg">Hi there,</span><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg">Code explains everything:</span></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_918642921984995860m_-484177411408662380Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span></span></div></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><br class="gmail_msg"></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">/// Maybe a bad API naming in Swift? See below:</span></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><br class="gmail_msg"></span></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">/// array1 can be array of any object that have a `count` method</span></div><div style="margin:0px;line-height:normal" 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">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> array1 = [[</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">String</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">]]()</span></div><div style="margin:0px;line-height:normal" 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">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> array2 :[</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">String</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">nil</span></div><div style="margin:0px;line-height:normal;min-height:15px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><br class="m_918642921984995860m_-484177411408662380webkit-block-placeholder gmail_msg"></div><div style="margin:0px;line-height:normal;min-height:15px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><br class="m_918642921984995860m_-484177411408662380webkit-block-placeholder gmail_msg"></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// I believe the confusion between `array.map` and `optionalArray.map` is really bad.</span></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// Because when you read code like this, you can not tell which is which:</span></div><div style="margin:0px;line-height:normal" 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">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array1.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">map</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">({$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">count</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">})</span></div><div style="margin:0px;line-height:normal" 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">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array2.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">map</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">({$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">count</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">})</span></div><div style="margin:0px;line-height:normal;min-height:15px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><br class="m_918642921984995860m_-484177411408662380webkit-block-placeholder gmail_msg"></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// It can be clearer:</span></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// 1, we pass `self.element` into the closure</span></div><div style="margin:0px;line-height:normal" 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">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array1.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">map</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">({$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">count</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">})</span></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">        </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// 2, we pass self directly into the closure</span></div><div style="margin:0px;line-height:normal" 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">_</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> = array2.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">mapMe</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">({$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">count</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">})</span></div></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"><br 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"><br 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">The mapFlat method is also problematic.</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"><br 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">Yours,</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">Jay Zhao</span></div></div></blockquote><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><span class="gmail_msg">_______________________________________________</span><br class="gmail_msg"><span class="gmail_msg">swift-evolution mailing list</span><br class="gmail_msg"><span class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a></span><br class="gmail_msg"><span class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class="gmail_msg"></div></blockquote></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>