zip
#define zip(...)
Construct a Zip object on the stack.
enumerate
#define enumerate(I)
Zip the iterable I with a Range object of the same length.
Usage
/* Iterate over two iterables at once */
var x = new(Array, Int, $I(100), $I(200), $I(130));
var y = new(Array, Float, $F(0.1), $F(0.2), $F(1.3));
foreach (pair in zip(x, y)) {
print("x: %$\n", get(pair, $I(0)));
print("y: %$\n", get(pair, $I(1)));
}
/* Iterate over iterable with count */
foreach (pair in enumerate(x)) {
print("%i: %$\n", get(pair, $I(0)), get(pair, $I(1)));
}
Multiple Iterator
The Zip type can be used to combine multiple iterables into one which is then iterated over all at once and returned as a Tuple. The Zip object only iterates when all of it's sub iterators have valid items. More specifically the Zip iteration will terminate if any of the sub iterators terminate.
struct Zip {
var iters;
var values;
};
$ alloc dealloc cast cmp eq neq gt lt ge le copy hash hash_data size swap assign name brief description definition get set mem rem key_type val_type foreach iter_init iter_next iter_type len new del construct destruct