<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>A quick-and-dirty way would be to explicitly cast to the protocol type before calling the function.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">let flatArray = (mapArray as SequenceType).flatten()<br></div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Or in this case you could just mapArray.flatMap()</div><div><br>On Dec 5, 2015, at 12:38 PM, Vinicius Vendramini &lt;<a href="mailto:vinivendra@gmail.com">vinivendra@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">So I was playing around with Sequences, and I came across a problem I haven't been able to solve in a decent way. I’ve reduced it to a simpler example here:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> array : [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>] = [<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span>]</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> mapArray = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">array</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span> { $0 }</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> flatArray = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">mapArray</span>.flatten() <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// Error!</span></div></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">This last line of code prints the following error:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><b class="">let flatArray = mapArray.flatten() // Error!</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">Swift.SequenceType:4:17: note: found this candidate</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; public func flatten() -&gt; FlattenSequence&lt;Self&gt;</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">Swift.CollectionType:4:17: note: found this candidate</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; public func flatten() -&gt; FlattenCollection&lt;Self&gt;</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">Swift.CollectionType:4:17: note: found this candidate</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; public func flatten() -&gt; FlattenBidirectionalCollection&lt;Self&gt;</b></div><div style="margin: 0px; line-height: normal;" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">As far as I understand it, the error happens because several protocols extensions implement the `flatten` method, and `mapArray` (which is of type `Array&lt;Optional&lt;Int&gt;&gt;`) conforms to a few of those, which means the compiler has no way of knowing which one I intend on using.</div><div class=""><br class=""></div><div class="">How do I solve this?</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=z0Ft8gvIaLt1zLwfkl4og6osLD9N8tlWJY1PY2zqWLXW6AUCPnOB1o9xfIVkBT7EkA9CEGSydcVMc1v4TL6nB0nE21DWkYMptNl-2F7jZLzzithZa7013s-2BChRCoJM-2BGk9OsnvmRaC30FTaE-2FVlHkvMUsvjdoeauxwvpsw5AzwcQe5GdMEuAtJvIppCfGmkNH-2BkV94ltvCGsiSnEht9rIX4gfedd27iMQvpZUmowhXKwQ-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;">

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></div></blockquote></body></html>