<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>I like the idea of having a mapping method which maps back to the actual type.</div><div>What about a more general approach? consider:</div><div><br></div><div>mappedSelf(transform: T -&gt; U) -&gt; Self&lt;U&gt;</div><div>filteredSelf(includeElement: T -&gt; Bool) <span style="background-color: rgba(255, 255, 255, 0);">-&gt; Self&lt;U&gt;</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Which can be added to other collections like Set and sequences like a lazy number sequence.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Best regards</span></div><div>- Maximilian</div><div><br>Am 13.04.2016 um 08:41 schrieb Jonathan Hull via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">I would really like to see something like the following added to the standard library:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>Dictionary<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> mapValues&lt;U&gt;(transform:(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Value</span>)-&gt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>)-&gt;[<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>] {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> output:[<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>] = [:]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> (k,v) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output[k] = transform(k,v)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> output</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">It comes up enough that I have had to add it to pretty much every one of my projects. &nbsp;I also don’t feel comfortable adding it to my frameworks, since I figure a lot of people are also adding something like this to their projects, and I don’t want to cause a conflict with their version. &nbsp;Prime candidate for the standard library.</div><div class=""><br class=""></div><div class="">I like calling it ‘mapValues' as opposed to providing an override for map, since it makes the specific behavior more clear. &nbsp;I would expect ‘map' to possibly map the keys as well (though there are issues where the new keys overlap). &nbsp;I suppose you could just have a bunch of overrides for map if the compiler becomes good enough at differentiating return types: (Value)-&gt;(Value), (Key,Value)-&gt;Value, (Key, Value)-&gt;(Key,Value)</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>