Prev | Current Page 264 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

decorate); // traces - > John
print(s, function(s){ return ???-- ??? + s + ??? --???; }); // traces -- John --
}
}
The second argument of the print() function is a typedef for a function that accepts a String as an
argument and returns a String . In the main() method the print() function is used passing the static
function quote() , then the instance function decorate() of the class StringDecoration , and finally
an inline function definition.
Iterators and Iterables
In the haXe standard library, two very commonly used typedef s are defined: Iterator < T > and
Iterable < T > .
Their definition is as follows:
typedef Iterator < T > = {
function hasNext() : Bool;
function next() : T;
}
typedef Iterable < T > = {
function iterator() : Iterator < T > ;
}
As you have already seen in Chapter 3 , those structures are defined to deal with object collections and
they are easily implemented in class definitions. In the example, a random iterator is defined. The
iterator will return a sequence of n random letters.


Pages:
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276