Deluge Data Types - Map

Overview

Map is a collection of key value pairs, where each unique key maps to a value. Keys and values can be of any data type say number, text, date, boolean etc. For example, the following table represents a map of books and their authors. Values will be added and retrieved based on the key.

Books (Key)Origin of speciesWar and peaceWealth of NationsPrincipia
Authors (Value)charles DarwinLeo TolstoyAdam SmithIssac Newton
  • key - string type
  • value - can be any type but will be returned as a string

If a value is added with an already existing key, it will overwrite the existing value. In the following example, productDetail is the map variable that holds the value of 'Quantity In Stock' as 10.

productDetail = {"Product Name" : "IPhone 4s", "Quantity In Stock" : 10};
//on executing the below script 'Quantity In Stock' will be updated by 20
productDetail.put("Quantity In Stock", 20);

As with lists, you can populate map key-value pairs when the map is declared by using curly brace ({}) syntax. Within the curly braces, specify the key first, then specify the value for that key using ":". For example,

My_Map = { "1" : "one", "2" : "two", "3" : "three", "4" : "four" };

In the above example, the value for the key "1" is one, and the value for the key "2" is two. To access the elements in a map, use the Map Methods (link) supported by Deluge.

Map -Built in functions

Functions that operate on Map expression are classified as Map functions. They include functions for returning the number which represent the size of the map, returning the list of keys containing in the map etc. Refer the topic Built-in-functions - Map for the complete list of Map functions.

Examples

myMap = map(); //create new map
myMap.put("name", "Zoho");
myMap.put("address", "Pleasanton, CA 94588, USA");
myMap.put("website", "www.zoho.com");
x=myMap.get("name"); //returns the value Zoho
x=myMap.size(); // returns the value 3

Share this post : FacebookTwitter