Array Comprehension
Starting from Haxe 3.0, the Haxe language supports Array comprehensions, using the following syntax:
var a = [for( x in 0...10 ) x]; trace(a); // [0,1,2,3,4,5,6,7,8,9]
Any Iterable value can be used in the for construct, just like a normal for.
Additionally, it is possible to filter the elements with an if test:
var b = [for( x in a ) if( x % 2 == 0 ) x]; trace(b); // [0,2,4,6,8]
Haxe's comprehensions also support while constructs and nested loops:
var c = [for( x in 0...4 ) for( i in 0...x+1 ) i]; trace(c); // [0,0,1,0,1,2,0,1,2,3]
var count = 10; var d = [while(count > 0) count-- ]; trace(d); // [10,9,8,7,6,5,4,3,2,1]
version #18412, modified 2013-05-07 15:40:41 by nadako