Ok. Good to hear that I&#39;m not too far off :)<br><br>Can you provide me with an example of a sequence type or two that has some map or other function that would benefit from an optimized wrapper? Or: under what circumstances would the stdlib implementation outperform mine? I&#39;m completely new to this all, and I&#39;m trying to understand. Could some random access collection type parallelize a filter? If you want I guarantee correct ordering, under what circumstances does some sequence type work better than mere iteration?<br><br><br><div class="gmail_quote"><div dir="ltr">fre. 17. jun. 2016 kl. 15.49 skrev Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>&gt;:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Jun 17, 2016 at 1:39 AM, Svein Halvor Halvorsen via<br>
swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br>
&gt; I&#39;m sure people here know about the problem that AnySequence, AnyGenerator,<br>
&gt; etc solves.<br>
&gt; In Swift, a protocol can have an associated type, which is kinda like<br>
&gt; generics, but you cannot declare a variable like this:<br>
&gt;<br>
&gt; let sequence: SequenceType&lt;Int&gt;<br>
&gt;<br>
&gt; If you want a sequence, any sequence, over ints you need to wrap the<br>
&gt; protocol in a new concrete, generic type, AnySequence&lt;T&gt; that itself<br>
&gt; implements the protocol SequenceType, and where the associated type Element<br>
&gt; is equal to the generic type T.<br>
&gt;<br>
&gt; The standard library does this. And, like many others, I have tried to<br>
&gt; implement this for my self, to try to better understand the problem, and I<br>
&gt; expected that I would end up with a design very similar to what the standard<br>
&gt; library does. However, I have not seen the need for the complex boxing<br>
&gt; mechanism. I&#39;m probably misunderstanding something, though.<br>
&gt;<br>
&gt; Can someone please look at this code, and give me constructive feedback? Is<br>
&gt; this a novel and working solution, or am I missing something?:<br>
<br>
Hi,<br>
<br>
Your design should work, but it won&#39;t provide optimal performance.<br>
Sequence has a lot of requirements that can be customized by the<br>
conforming type (e.g., map()).  We need to forward those to the<br>
original type to get the best performance.<br>
<br>
While you can create a closure for each of the forwarded methods,<br>
let&#39;s say n in total, it is n times more wasteful compared to using<br>
just a single reference like the standard library does.<br>
<br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;*/<br>
</blockquote></div>