AH!  I wasn't familiar enough with the LazyCollectionType protocol to
realize that its map() function had a different signature.

So, presumably, if I pass a non-throwing closure, the compiler will choose
the lazy map().  However, it's not immediately obvious to me why it would
be chosen.  Is it because the LazyCollectionType version of map() "shadows"
the CollectionType whenever either one could be chosen (since
LazyCollectionType extends CollectionType)?  Or is it because the function
with the more restrictive argument type is always chosen when more than one
version of the function could match?


On Tue, Jun 28, 2016 at 5:38 PM, Dmitri Gribenko <griboz...@gmail.com>
wrote:

> On Tue, Jun 28, 2016 at 3:37 PM, Aaron Bohannon via swift-users
> <swift-users@swift.org> wrote:
> > Does the code below have a well-defined behavior?
>
> It invokes the eager map() that is available on Array.lazy.
> Array.lazy is a collection, so it has an eager map() from the
> Collection protocol.  The lazy map() does not accept a throwing
> closure, so it does not match and the type checker chooses the eager
> one.
>
> Arguably, in non-generic context this code should not type check.
>
> 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 <griboz...@gmail.com>*/
>
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to