I've been thinking about this issue some more and it occurs to me that we might be thinking about this the wrong way.

Providing a :fillin() adverb on C<zip> is a suboptimal solution, because it implies that you would always want to fill in *any* gap with the same value. While that's likely in a two-way zip, it seems much less likely in a multiway zip.

So I now propose that C<zip> works like this:

        C<zip> interleaves elements from each of its arguments until
        any argument is (a) exhausted of elements I<and> (b) doesn't have
        a C<fill> property.

        Once C<zip> stops zipping, if any other element has a known finite
        number of unexhausted elements remaining, the <zip> fails.

In other words, you get:

     @i3 =   1..3   ;
     @i4 =   1..4   ;
     @a3 = 'a'..'c' ;

     zip(@a3, @i3)                  # 'a', 1, 'b', 2, 'c', 3
     zip(@i3, @i4)                  # fail

     zip(100..., @a3, @i3)          # 100, 'a', 1, 101, 'b', 2, 102, 'c', 3
     zip(100..., @a3, @i4)          # fail

     zip(@a3 but fill(undef), @i4)  # 'a', 1, 'b', 2, 'c', 3, undef, 4

     zip(1..6, @i3 but fill(3), @i4 but fill('?'))
                                    # 1,1,1,2,2,2,3,3,3,4,3,4,5,3,'?',6,3,'?'


Damian

Reply via email to