List class | systype.h[932], misc.t[2219], reflect.t[373]

The native list type

Modified in misc.t[2219]:
Add some utility methods to List.

Modified in reflect.t[373]:
Modify the List intrinsic class to provide a to-symbol mapping

`intrinsic class List : Collection`

Superclass Tree (in declaration order)

`List`
`Collection`
`Object`

Subclass Tree

(none)

Global Objects

(none)

Summary of Properties

``

``

``

(none)

Summary of Methods

`append appendUnique car cdr countOf countWhich element find forEach forEachAssoc getUnique indexOf indexOfMax indexOfMin indexWhich insertAt intersect join lastIndexOf lastIndexWhich lastValWhich length mapAll matchProto maxVal minVal overlapsWith prepend removeElementAt removeRange shuffle sort splice strComp sublist subset toList valToSymbol valWhich`

Inherited from `Collection` :
`createIterator createLiveIterator`

Inherited from `Object` :
`callInherited cf checkDisplay display displayAlt getPropList getPropParams getSuperclassList isClass isTransient ofKind propDefined propInherited propType`

Properties

(none)

Methods

`append (val)` | `systype.h[1037]`

append an element - this works almost exactly like the concatation operator ('+'), but if the argument is a list, this simply adds the list as a new element, rather than adding each element of the list as a separate element

`appendUnique (lst)` | `systype.h[1029]`

append the elements of the list 'lst' to the elements of this list, then remove repeated elements in the result; returns a new list with the unique elements of the combination of the two lists

`car ( )` | `systype.h[968]`

car/cdr - head/tail of list

`cdr ( )` | `systype.h[969]`

no description available

`countOf (val)` | `systype.h[1016]`

count the number of elements with the given value

`countWhich (cond)` | `systype.h[1019]`

count the number of elements for which the callback returns true

`element (i)` | `misc.t[2314]`

Returns the ith member of the list if there is one, or nil otherwise

`find (ele)` | `misc.t[2283]`

find a list element - synonym for indexOf

`forEach (func)`OVERRIDDEN | `systype.h[986]`

Invoke the callback func(val) on each element, in order from first to last. No return value.

`forEachAssoc (func)` | `systype.h[1101]`

Invoke the callback func(index, val) on each element, in order from first to last. No return value.

`getUnique ( )` | `systype.h[1022]`

get a new list consisting of the unique elements of this list

`indexOf (val)` | `systype.h[965]`

get the index of the first match for the given value

`indexOfMax (func?)` | `systype.h[1169]`

Get the index of the list item with the maximum value. If 'func' is missing, this simply returns the index of the list element with the largest value, comparing the element values as though using the '>' and '<' operators. If 'func' is specified, it must be a function; it's called as func(x) for each value in the list, and the result of the overall call is the index of the element for which func(x) returns the greatest value. For example, if you have a list of strings l, l.indexOfMax({x: x.length()}) returns the index of the longest string in the list.

`indexOfMin (func?)` | `systype.h[1146]`

Get the index of the list item with the minimum value. If 'func' is missing, this simply returns the index of the list element with the smallest value, comparing the element values as though using the '>' and '<' operators. If 'func' is specified, it must be a function; it's called as func(x) for each value in the list, and the result of the overall call is the index of the element for which func(x) returns the smallest value. For example, if you have a list of strings l, l.indexOfMin({x: x.length()}) returns the index of the shortest string in the list.

`indexWhich (cond)` | `systype.h[980]`

Find the first element for which the given condition is true, and return the index of the element. Applies the callback function (which encodes the condition to evaluate) to each element in turn, starting with the first. For each element, if the callback returns nil, proceeds to the next element; otherwise, stops and returns the index of the element. If the callback never returns true for any element, we'll return nil.

`insertAt (startingIndex, val, ...)` | `systype.h[1077]`

Insert one or more elements at the given index. If the starting index is 1, the elements will be inserted before the first existing element. If the index is one higher than the number of elements, the elements will be inserted after all existing elements. If the index is negative, it counts backwards from the end of the list: -1 inserts before the last element, -2 inserts before the second to last, and so on. If the index is zero, the new elements are inserted after the last element.

Note that a list value argument will simply be inserted as a single element.

Returns a new list with the value(s) inserted.

`intersect (other)` | `systype.h[962]`

intersect with another list

`join (sep?)` | `systype.h[1133]`

Combine the list elements into a string. This converts each element into a string value using the usual default conversions (or throws an error if string conversion isn't possible), then concatenates the values together and returns the result. If 'separator' is provided, it's a string that's interposed between elements; if this is omitted, the elements are concatenated together with no extra characters in between.

`lastIndexOf (val)` | `systype.h[996]`

find the last element with the given value, and return its index

`lastIndexWhich (cond)` | `systype.h[1007]`

Find the last element for which the condition is true, and return the index of the element. Applies the callback to each element in turn, starting with the last element and working backwards. For each element, if the callback returns nil, proceeds to the previous element; otherwise, stops and returns the index of the element. If the callback never returns true for any element, we'll return nil.

`lastValWhich (cond)` | `systype.h[1013]`

Find the last element for which the condition is true, and return the value of the element

`length ( )` | `systype.h[956]`

get the number of elements in the list

`mapAll (func)`OVERRIDDEN | `systype.h[953]`

Apply the callback function to each element of this list, and return a new list consisting of the results. Effectively maps the list to a new list using the given function. Suppose the original list is

[x, y, z]

Then the result list is

[func(x), func(y), func(z)]

`matchProto (proto)` | `misc.t[2230]`

Check the list against a prototype (a list of data types). This is useful for checking a varargs list to see if it matches a given prototype. Each prototype element can be a TypeXxx type code, to match a value of the given native type; an object class, to match an instance of that class; 'any', to match a value of any type; or the special value '...', to match zero or more additional arguments. If '...' is present, it must be the last prototype element.

`maxVal (func?)` | `systype.h[1179]`

Get the maximum value in the list. If 'func' is missing, this returns the largest element value. If 'func' is specified, it must be a function; it's called as func(x) for each value in the list, and the result of the overall method call is the element value x that maximizes func(x). For example, if l is a list of strings, l.maxVal({x: x.length()}) returns the longest string.

`minVal (func?)` | `systype.h[1156]`

Get the minimum value in the list. If 'func' is missing, this returns the minimum element value. If 'func' is specified, it must be a function; it's called as func(x) for each value in the list, and the result of the overall method call is the element value x that minimizes func(x). For example, if l is a list of strings, l.minVal({x: x.length()}) returns the shortest string.

`overlapsWith (lst)` | `misc.t[2308]`

Determine whether this list has any elements in common with lst

`prepend (val)` | `systype.h[1060]`

Prepend an element - this inserts the value before the first existing element.

`removeElementAt (index)` | `systype.h[1085]`

Delete the element at the given index, reducing the length of the list by one element. If the index is negative, it counts from the end of the list: -1 is the last element, -2 is the second to last, etc. Returns a new list with the given element removed.

`removeRange (startingIndex, endingIndex)` | `systype.h[1095]`

Delete the range of elements starting at startingIndex and ending at endingIndex. The elements at the ends of the range are included in the deletion. If startingIndex == endingIndex, only one element is removed. If either index is negative, it counts from the end of the list: -1 is the last element, -2 is the second to last, etc. Returns a new list with the given element range removed.

`shuffle ( )` | `misc.t[2289]`

shuffle the list: return a new list with the elements of this list rearranged into a random order

`sort (descending?, comparisonFunction?)` | `systype.h[1054]`

Sort the list, returning a new list. If the 'descending' flag is provided and is not nil, we'll sort the list in descending order rather than ascending order.

If the 'comparisonFunction' argument is provided, it must be a callback function; the callback takes two arguments, and returns an integer less than zero if the first argument value is less than the second, zero if they're equal, and an integer greater than zero if the first is greater than the second. If no 'comparisonFunction' argument is provided, or it's provided and its value is nil, we'll simply compare the list elements as ordinary values. The comparison function can be provided for caller-defined orderings, such as ordering a set of objects.

`splice (idx, del, ...)` | `systype.h[1122]`

Splice new values into the list. Deletes the 'del' list items starting at 'idx', then inserts the extra arguments in their place. Returns a new list reflecting the spliced values. To insert items without deleting anything, pass 0 for 'del'. To delete items without inserting anything, omit any additional arguments.

`strComp (lst, cmp)` | `misc.t[2324]`

Compare two lists of strings using the cmp StringComparator; return true if all the corresponding strings in the two lists are the same (according to cmp) and nil otherwise.

`sublist (start, len?)` | `systype.h[959]`

extract a sublist

`subset (func)` | `systype.h[939]`

Select a subset of the list: returns a new list consisting only of the elements for which the callback function 'func' returns true.

`toList ( )` | `misc.t[2280]`

toList() on a list simply returns the same list

`valToSymbol ( )`OVERRIDDEN | `reflect.t[374]`

no description available

`valWhich (cond)` | `systype.h[993]`

Find the first element for which the given condition is true, and return the value of the element. Returns nil if no item satisfies the condition.

Adv3Lite Library Reference Manual
Generated on 13/06/2025 from adv3Lite version 2.2.1