[swift-users] LazyCollection.map()
Dmitri Gribenko
gribozavr at gmail.com
Tue Jun 28 20:09:50 CDT 2016
On Tue, Jun 28, 2016 at 6:07 PM, Aaron Bohannon <aaron678 at gmail.com> wrote:
> 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?
LazyCollectionType.map() does not shadow Collection.map(), but the
type checker prefers the lazy one because LazyCollectionType refines
Collection. Basically, it prefers the more refined one, but the other
one is still an option.
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-users
mailing list