Luke Palmer wrote:
Joe Gottman writes:Doesn't C<zip> go until the longest input is exhausted, returning undef at the end of the shorter ones?
multi sub kv (Array @array : [EMAIL PROTECTED]) returns List
Returns the indexes and associated values stored in @array, lazily and in
order by index. Optionally, only those of the slice defined by @indices.
This one is real easy:
multi sub kv (@array) returns List {
zip(1...; @array);
}
multi sub kv (@array) returns List { zip([EMAIL PROTECTED] ; @array); }
Should work, though.
Array @array means an array of arrays.Grr. Another thing I knew better on and was getting wrong. If nothing else, I'm getting used to thinking Perl 6 more and more by writing this thing.
Yea, but I saw Larry mention somewhere about supplying an optional list of values to kv, etc. Forget exactly where, but I know I saw it. At least, that was a reference to the Hash kv, where it makes sense, when it's not painfully obvious that the keys mentioned already exist.The [EMAIL PROTECTED] parameter seems superflous, since you could just do:
for @array[1..10].kv -> $k, $v {...}
My thinking is that the kv/values/etc method of supplying a slice omits elements that don't exist from the output, while the subscript slices would generate undef. Also, I've taken a step and made it where it's now:
multi sub keys (@array : Any|Junction [EMAIL PROTECTED]) returns Int|List
multi sub kv (@array : Any|Junction [EMAIL PROTECTED]) returns Int|List
multi sub pairs (@array : Any|Junction [EMAIL PROTECTED]) returns Int|(List of Pair)
multi sub values (@array : Any|Junction [EMAIL PROTECTED]) returns Int|List
Which "slices" based on C<$index ~~ any(@indextests)>, which seems a bit more flexible.
Thanks to Joe for pointing out the missing functions. They've been added locally and will be posted shortly. (Any others?)
-- Rod Adams