Task

The goal is to create an associative array (also known as a dictionary, map, or hash).



Related tasks:

 Associative arrays/Iteration
 Hash from two arrays


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


// In Lasso associative arrays are called maps
 
// Define an empty map
local(mymap = map)
 
// Define a map with content
local(mymap = map(
	'one'	= 'Monday',
	'2'	= 'Tuesday',
	3	= 'Wednesday'
))
 
// add elements to an existing map
#mymap -> insert('fourth' = 'Thursday')
 
// retrieve a value from a map
#mymap -> find('2') // Tuesday
'<br />'
#mymap -> find(3) // Wednesday, found by the key not the position
'<br />'
 
// Get all keys from a map
#mymap -> keys // staticarray(2, fourth, one, 3)
'<br />'
 
// Iterate thru a map and get values
with v in #mymap do {^
	#v
	'<br />'
^}
// Tuesday<br />Thursday<br />Monday<br />Wednesday<br />
 
// Perform actions on each value of a map
#mymap -> foreach => {
	#1 -> uppercase
	#1 -> reverse
}
#mymap // map(2 = YADSEUT, fourth = YADSRUHT, one = YADNOM, 3 = YADSENDEW)