Prev | Current Page 209 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

charAt(0);
var y : String = b.charAt(0);
return if ( x == y ) 0 else if ( x < y ) -1 else 1;
}
var fun2 = function( a : String, b : String ) : Int
{
return if ( a == b ) 0 else if ( a < b ) -1 else 1;
}
// Outputs: [???four???, ???five???, ???one???, ???six???, ???two???, ???three???]
strArr.sort( fun1 );
trace(strArr);
// Outputs: [???five???, ???four???, ???one???, ???six???, ???three???, ???two???]
strArr.sort( fun2 );
trace(strArr);
}
}
As you can imagine, you can perform some very elaborate sorting methods on pretty much anything.
Many languages have a single sort method that try to sort on some representation of the contained items,
whereas haXe Array sort method provides ultimate control over how your data is organized.
The Lambda Class
The Lambda class contains several methods for modifying the content of Arrays and iterators in a fashion
that is oriented toward a functional style of programming. To the greater extent, most of the methods are
merely variations of methods accepting local functions as you saw earlier in this chapter, with the
exception that they affect different collections than you ??™ ve otherwise seen.


Pages:
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221