Map

abstract Map<K, V>Available in flash8, flash, neko, js, php, cpp, cs, javaMap allows key to value mapping for arbitrary value types, and many key types.
This is a multi-type abstract, it is instantiated as one of its specialization types depending on its type parameters.
A Map can be instantiated without explicit type parameters. Type inference will then determine the type parameters from the usage.
Maps can also be created with key1 => value1, key2 => value2 syntax.
Map is an abstract type, it is not available at runtime.
version #18384, modified 2013-05-01 12:00:35 by api
3 comments
  • Jul 21, 2013 at 09:37

    What are key1 => value1, key2 => value2 syntax?

  • Aug 15, 2013 at 09:49

    As said in Haxe 3 New Features, the key => value syntax is explained by Jason on his blog.

  • Aug 21, 2013 at 19:32

    For completeness of this page here is the example from jasononeil.com.au blog:

    var map1 = [ 1=>"one", 2=>"two", 3=>"three" ];
    $type (map1); // Map<Int, String>
    
    var map2 = [ "one"=>1, "two"=>2, "three"=>3 ];
    $type (map2); // Map<String, Int>
    
    var map3 = [
        Date.now() => "Today",
        Date.now().delta(24*60*60*1000) => "Tomorrow",
        Date.now().delta(-24*60*60*1000) => "Yesterday"
    ];
    $type (map3); // Map<Date, String>
    
    var map4 = [
        { name: "Tony Stark" } => "Iron Man",
        { name: "Peter Parker" } => "Spider Man"
    ];
    $type (map4); // Map<{ name : String }, String>
    
    var map5 = [
        [1,2] => ["one","two"],
        [3,4] => ["three","four"],
    ];
    $type (map5); // Map<Array<Int>, Array<String>>