Skip to content


IterTools introduces some common Iterator-type manipulation routines into haXe.  You’ll want to include the library IterTools inside your build file as normal.  Most of the methods will function pretty similarly to the itertools package for python.

for instance, you can make a combinator iterator (identical to the Array combinator) as follows:

var l = new List<Int>();
for (i in 0...100) l.add(i);
var itr = IterTools.combinator(l,3);
for (i in itr){

And you’ll have an iterator over three randomly chosen elements of the list “l”.

There’s a few notes about these methods:

  1. I’ve had to handle functions that take Iterable<Iterable<T>> arguments in a slightly awkward way.  Please see my blog post about this.
  2. starmap() uses the Reflect API, so normal cautions apply.  It is possible to call a static function using starmap, you can simply pass an anonymous object {} for the first object argument, and then the static method itself (Math.pow for instance) for the second argument.  However, you can only pass a function that takes a maximum of 6 parameters.

There’s many more methods, check the documentation here.

%d bloggers like this: