Ok. Good to hear that I'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'm completely new to this all, and I'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 <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>:<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 <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:<br>
> I'm sure people here know about the problem that AnySequence, AnyGenerator,<br>
> etc solves.<br>
> In Swift, a protocol can have an associated type, which is kinda like<br>
> generics, but you cannot declare a variable like this:<br>
><br>
> let sequence: SequenceType<Int><br>
><br>
> If you want a sequence, any sequence, over ints you need to wrap the<br>
> protocol in a new concrete, generic type, AnySequence<T> that itself<br>
> implements the protocol SequenceType, and where the associated type Element<br>
> is equal to the generic type T.<br>
><br>
> The standard library does this. And, like many others, I have tried to<br>
> implement this for my self, to try to better understand the problem, and I<br>
> expected that I would end up with a design very similar to what the standard<br>
> library does. However, I have not seen the need for the complex boxing<br>
> mechanism. I'm probably misunderstanding something, though.<br>
><br>
> Can someone please look at this code, and give me constructive feedback? Is<br>
> this a novel and working solution, or am I missing something?:<br>
<br>
Hi,<br>
<br>
Your design should work, but it won'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'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<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>>*/<br>
</blockquote></div>