Export to GitHub

visage - issue #23

Map Data Type


Posted on Jan 13, 2011 by Grumpy Panda

Most programming languages have a common Map data type or something similar. Visage would greatly benefit from having a Map data type, which would avoid having to create and use a custom class that acts like one, or depend on one supplied by the target platform that does not integrate with Visage nicely.

Also by having Map present data binding can be done on keys/values, filtering and map operations performed on it etc. Below are some suggestions on the syntax and use of the Map data type (subject to change):


// Define map using type inference with keys and values. def map1 = ["30 seconds" -> "30000", "1 minute" -> "60000", "5 minutes" -> "300000", "10 minutes" -> "600000", "15 minutes" -> "900000", "30 minutes" -> "1800000", "1 hour" -> "3600000"];

// Define map using strict typing (String for keys, Integer for values). def map2: [String, Integer] = ["30 seconds" -> 30000, "1 minute" -> 60000, "5 minutes" -> 300000, "10 minutes" -> 600000, "15 minutes" -> 900000, "30 minutes" -> 1800000, "1 hour" -> 3600000];

// Add a new entry (key, value) to map2. Deliberately added an extra zero // to demonstrate how a value can be changed for a corresponding key. insert "10 seconds" -> 100000 into map2;

// Change the value for the "10 seconds" key in map2. map2["10 seconds"] = 10000; // Alternative way to change the value for "10 seconds" if the key // doesn't exist. insert "10 seconds" -> 10000 into map2;

// Remove an existing entry (key: "10 seconds") from map2. delete "10 seconds" from map2; // Alternative way to remove the entry.

delete map2["10 seconds"];

All keys in defined Maps would be unique. The following functions would be built into Map (subject to change):

  • keys (returns a sequence)
  • values (returns a sequence)

Comment #1

Posted on Jan 13, 2011 by Grumpy Panda

In the JavaFX bug DB the Map data type is one of the most requested features for JavaFX Script (dating all the way back to 5 Feb 2008).

====================================================

http://javafx-jira.kenai.com/browse/JFXC-642

Status: New

Labels:
Type-Enhancement Priority-High