« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

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.

Examples

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)));
}

Zip


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.

Definition

struct Zip {
  var iters;
  var values;
};

Derives

Implements

  • Assignassign
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Newnew del construct destruct

Back