Why VoltScript Collections and Maps?
Historically, the core LotusScript and VoltScript languages have had Arrays and Lists. And while these are useful, they are not as robust as the collection handling found in modern programming languages. Enter the VoltScript Collections classes.
The key focus for the VoltScript classes provided by VoltScript Collections is simplicity and ease of use.
Arrays
- can contain any data type, including classes and Lists.
- are unsorted.
- are not unique.
- are 0 indexed (unless
Option Base
is used, not recommended).- allow access based on index or via iteration (such as
ForAll
or looping).- ArrayGetIndex returns a Variant, which is numeric if the element is in the index or NULL if not.
- can contain any data type, including classes and Lists.
- are a keyed unsorted map with string keys.
- have unique keys.
- require
IsElement()
to check for existence.- allow access based on key or via
ForAll
iteration.- require looping via
ForAll
iteration to get element count- need to use
Erase
to remove an element or the entire list from memory.
Warning
VoltScript is designed for middleware, so any data has to be retrieved over HTTP(S). As a result, optimizing performance for large collections is not a priority for the framework, because performance will always be compromised for large collections in retrieving the data from whatever database it resides in and / or sending the data to the end user.
This means you need to work with smaller sets of data to maximize performance.
The classes provide:
- Simple classes for collections and maps.
- Pair classes, the basis of an element in a map, but also simple dictionary data types.
- Sorted and unique options for collections.
- Sorted options for maps (maps are always unique).
- A basic comparator that works for scalars without the developer needing to pass anything.
- A simple comparator to compare based on the same datatype.
- Extensible comparators for sorting and uniqueness. The Comparator defines sort order (ascending or descending) and is used to check for matches on
getIndex()
,contains()
,remove()
andreplace()
operations. reverse()
method on collections and maps to change sort order. Subsequent additions honor the amended sort order.getIndex()
,remove()
andreplace()
methods to manipulate collections, with relevant methods also for maps.join()
method on collections to create string of scalars.toJson()
andfromJson()
methods.filter()
,clone()
andtransform()
methods to manipulate collections and maps.lock()
andunlock()
methods to prevent inadvertent changes when passing to other functions.collectValues()
method to convert map values into a collection.collectKeys()
method to retrieve map keys as a collection.getAndRemoveFirst()
methods to provide the functionality of a Queue (FIFO).getAndRemoveLast()
methods to provide the functionality of a Stack (LIFO).