HaxeDoc2

(やまだぃちぅ) #1

26 // Maps iterate over their valuesby
27 // default
28 var valueSum;
29 for (value in map4){
30 trace(value); // Monday \nTuesday
31 }
32
33 // Can iterate over keys by usingthe
34 // keys() method
35 for (key in map4.keys()) {
36 trace(key); // M \n T
37 }
38
39 // Like arrays, a new Map canbe made using
40 // comprehension
41 var map5 =[
42 for (key in map4.keys())
43 key => "FRIDAY!!"
44 ];
45 // {M => FRIDAY!!, T => FRIDAY!!}
46 trace(map5);
47 }
48 }


See theMap APIfor details of its methods.
Under the hood, aMapis an abstract (2.8) type. At compile time, it gets converted to one of
several specialized types depending on thekeytype:


  • String:haxe.ds.StringMap

  • Int:haxe.ds.IntMap

  • EnumValue:haxe.ds.EnumValueMap

  • {}:haxe.ds.ObjectMap


TheMaptype does not exist at runtime and has been replaced with one of the above objects.
Map defines array access (2.8.3) using its key type.

10.2.6 Option


An option is an enum (2.4) in the Haxe Standard Library which is defined like so:
1 enum Option<T>{
2 Some(v:T);
3 None;
4 }
It can be used in various situations, such as communicating whether or not a method had a
valid return and if so, what value it returned:
1 import haxe.ds.Option;
2
3 class Main {
4 static public function main() {
Free download pdf