This type provides the core map class for Boxlang.
Structs are highly versatile and are used for organizing and managing related data.
Types of Structs in BoxLang: ,,DEFAULT, CASE_SENSITIVE, LINKED, LINKED_CASE_SENSITIVE, SORTED, WEAK, SOFT,,
DEFAULT: These are the basic structures where each key is associated with a single value. Keys are case-insensitive and can be strings or symbols.
Nested Structs: Structs can contain other structs as values, allowing for a hierarchical organization of data.
CASE_SENSITIVE: By default, BoxLang structs are case-insensitive. However, you can create case-sensitive structs if needed.
LINKED, LINKED_CASE_SENSITIVE (Ordered Structs): This implementation of a Struct maintains keys in the order they were added.
SORTED: This implementation of a Struct maintains keys in specified sorted order.
WEAK: This implementation of a Struct uses weak references for keys.
SOFT: This implementation of a Struct uses a default struct with values wrapped in a SoftReference.
Examples
Creating structs using the function structNew
// Create a default struct ( unordered )
myStruct = structNew();
// Create an ordered struct which will maintain key order of insertion
myStruct = structNew( "ordered" );
// Create a case-sensitive struct which will require key access to use the exact casing
myStruct = structNew( "casesenstive" );
myStruct[ "cat" ] = "pet";
myStruct[ "Cat" ] = "wild";
// Create a sorted struct
myStruct = structNew( "sorted", "textAsc" )
Creating structs using object literal syntax
// Create an empty default struct ( unordered )
myStruct = {};
// Create an empty struct and populate it with values
animals = {
cow: "moo",
pig: "oink"
};
// Create an ordered struct which will maintain key order of insertion
// Note that you must provide the ordered struct with data to prevent confusion as to whether it is an array or struct
orderedAnimals = [
cow: "moo",
pig: "oink"
];