[swift-evolution] zip3, zip4, ...
Erica Sadun
erica at ericasadun.com
Sun Dec 6 17:44:07 CST 2015
Is there an implementation in the stdlib for (T?, T?) like this?
> On Dec 6, 2015, at 4:37 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>
> On Sun, Dec 6, 2015 at 3:34 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> It's pretty easy to build your own Zips. Not sure the language really needs this. For example, I recently built a zip that produces (T?, T?) which fills one of the two with nil until both lists are consumed:
>
> func longZip<S0: SequenceType, S1: SequenceType>(seq0: S0, _ seq1: S1) ->
> AnyGenerator<(S0.Generator.Element?, S1.Generator.Element?)> {
>
>
> Just wanted to point out that AnyGenerator has an inherent cost from the type erasure. The implementation in the standard library uses generics and is fully optimizable.
>
> 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 <mailto:gribozavr at gmail.com>>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/4d7bcfae/attachment.html>
More information about the swift-evolution
mailing list