Loop over multiple arrays simultaneously: Difference between revisions

Content added Content deleted
Line 3,101:
Simplest iteration with an ordinary "loop" that will error on uneven sizes
<lang tailspin>
def x: ['a', 'b', 'c'];
def y: ['A', 'B', 'C'];
def z: [1, 2, 3];
 
1..$x::length -> '$x($it);$y($it);$z($it);
Line 3,117:
<lang tailspin>
templates transpose
def a: $it;
def n: $it(1)::length;
[ 1..$n -> $a(1..-1; $it) ] !
end transpose
Line 3,127:
A more complex transpose that uses "foreach" more in line with the task proposal and handles uneven arrays
<lang tailspin>
def u: ['a', 'b'];
def v: ['A', 'B', 'C'];
def w: [1];
 
templates transpose2
@: [];
$it... -> [i](
<?($i <..$@transpose2::length>)> ..|@transpose2($i): $it;
<> ..|@transpose2: [$it];) -> void
$@ !
end transpose2