<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="">I think that use of map is generally discouraged. forEach would probably be more explicit, or a for-loop.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 10 Jan 2016, at 18:58, 肇鑫 via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">You can use dictionary in a map. You just ignore the return value of the map.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default"><div class="gmail_default"><font face="georgia, serif" class="">var dic = [Int:String]()</font></div><div class="gmail_default"><font face="georgia, serif" class="">var index = 0</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">["John", "Mike", "Amy", "Kavin"].map {</font></div><div class="gmail_default"><font face="georgia, serif" class=""> dic.updateValue($0, forKey: index)</font></div><div class="gmail_default"><font face="georgia, serif" class=""> index += 1</font></div><div class="gmail_default"><font face="georgia, serif" class="">}</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">print(dic) // [2: "Amy", 0: "John", 1: "Mike", 3: "Kavin"]</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">zhaoxin</font></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 11, 2016 at 1:50 AM, Kenny Leung via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All.<br class="">
<br class="">
I find that instead of using map() on arrays, I more often use an operation that returns a dictionary from an array. A common case is fetching an array of data, then creating a local cache of it indexed by ID.<br class="">
<br class="">
Is there a name for this operation? Is this something that others would like to see added to the standard library?<br class="">
<br class="">
-Kenny<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><br class="">Owen Zhao<br class=""></div></div></div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B3usexigrc8Iux9vXvgEAL0wRBdvtEFYxIxVfpyrhimQ4cGMsUZ-2B8-2BzVACTkBFoqIlPq4LVSf1ja8P72Sb-2FyyYt9BGH7M4C6MzLueO2GJhnZPKVrov-2Bnlo8QRW-2F1jqAtsX8ozJnv60diTlz-2FdZn7ZRo7T-2FlH8GS9OrtmYfgoyV-2BeWujH-2BMRrf9qDt7r2azAtgA-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>