<div dir="ltr">Hi Dmitri,<div><br></div><div>Cool, thanks, it's in the making! Sorry I was really busy this week.</div><div><br></div><div>Can you tell me why is it required to have different implementation for Forward and Bidirectional LazyCollectionTypes?</div><div><br></div><div>Otherwise it's all clear!</div><div><br></div><div>Thanks a lot!</div><div><br></div><div>Cheers,</div><div><br></div><div>Mark</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 22 Feb 2016 at 02:55 Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Feb 14, 2016 at 4:12 AM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>> wrote:<br>
> On Sun, Feb 14, 2016 at 2:51 AM, Mark Aron Szulyovszky via<br>
> swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
>> Problem:<br>
>> .prefix() works eagerly even on LazyCollectionType. This means access is not<br>
>> O(1).<br>
>><br>
>> Implications:<br>
>> There's no way to only get the first N elements of a lazy sequence without a<br>
>> nasty for loop. If prefix() used on a lazy sequence, it'll trigger<br>
>> computation on the whole array, just to return the first N elements.<br>
>><br>
>> Proposal:<br>
>> It would be more more useful if lazy.<insert methods here>.prefix() returned<br>
>> LazyPrefixCollection<Generator.Element><br>
>> instead of<br>
>> Slice<LazyCustomCollection<Range<Generator.Element>>>.<br>
><br>
> Thanks, Mark!<br>
><br>
> I think this would be a good addition for forward and bidirectional<br>
> collections. You'd need two separate implementations for forward and<br>
> bidirectional wrappers.<br>
><br>
> For random-access collections, the eager implementation is optimal<br>
> (finding the end index runs in O(1) and Slice<> does not introduce any<br>
> constant factor compared to non-trivial wrappers), and we should keep<br>
> that behavior by adding an overload that would return a<br>
> LazyCollection<Slice<Base>>.<br>
<br>
Hi Mark,<br>
<br>
I think you can continue with writing a formal proposal in the<br>
swift-evolution repository, presenting the full API that you are<br>
proposing.<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>