[swift-evolution] Prosposal: LazyCollectionType.prefix() to return a lazy collection
Dmitri Gribenko
gribozavr at gmail.com
Sun Feb 28 15:49:50 CST 2016
On Sun, Feb 28, 2016 at 5:36 AM, Mark Aron Szulyovszky
<mark.szulyovszky at gmail.com> wrote:
> Hi Dmitri,
>
> Cool, thanks, it's in the making! Sorry I was really busy this week.
>
> Can you tell me why is it required to have different implementation for
> Forward and Bidirectional LazyCollectionTypes?
Hi Mark,
The reason to have different implementations is so that a result of
applying prefix() to a bidirectional collection is also a
bidirectional collection. If we had just one lazy wrapper, the result
of prefix() would always be a forward collection. You might also need
to do the same for random access, I haven't thought it through well
enough to say if it would certainly be needed. But we want
xs.lazy.prefix() to preserve the collection category (forward,
bidirectional, random access) in the result.
Creating multiple types wouldn't be needed if we had a generics
feature that we don't have now -- conditional protocol conformances.
We want that, and will eventually have it, but for now, we have to go
with multiple types.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-evolution
mailing list