MM-Talk list functions
List.AddFirst
[Object]→List
Result: The AddFirst
function returns a new list with the transferred object inserted at the beginning.
List.AddLast
[object]→List
Result: The AddLast
function returns a new list, at the end of which the transferred object is inserted.
List.append
[MoreLists]→List
Result: The Append
function returns a list that contains a concatenation of all transferred lists.
Example: Append(List(1;2);List(4;3)) results in the list <1,2,4,3>.
ListOfLists.Concatenate→List
Result: With the Concatenate
function, lists are joined together in a similar way to the Append
function. Here, the lists to be added to each other are transferred in the form of elements of a list.
Beispiel
Concatenate
(List(List(1;2);List(4;3))) results in list <1,2,4,3>.
List.Contains
[Object]→Boolean
Result: The Contains
function tests whether the list contains the transferred object. It returns "True" if the object occurs, otherwise the value "False".
List.DeleteIf
[test function;selector function]→List
List.DeleteIfNot
[test function;selector function]→List
Selector function: see List.sort
function
Test function: A single-digit function that is to return a Boolean value and is used as a test criterion.
Result: The DeleteIf
and DeleteIfNot
functions return the partial list of all objects that fulfill the test criterion (for the selector function result) or (in the case of DeleteIf
) do not fulfill it.
Beispiel
If $List is a list of bookings, $List.DeleteIf
[#Booking_Canceled] returns the list of all occurring bookings that are not canceled.
EmptyList→List
Result: The EmptyList
function returns an empty list.
List.Find
[Test function;Selector function]→Object
Selector function: see List.sort
function
Test function: A single-digit function that is to return a Boolean value and is used as a test criterion.
Result: The Find
function returns the first object in the list that fulfills the test criterion (for the selector function result).
Beispiel
Example: If $List is a list of bookings, $List.Find
[#Booking_Canceled] returns the first canceled booking in the list.
List.First→Object
Result: The First
function returns the first element of the list.
List.fold
[function;start value]→object
Result: The <function> is applied successively to each list element in the second argument and the previous function result (the <start value> the first time) in the first argument. The overall result is the result of the last evaluation. The Fold
iterator function is very abstract and versatile, as the intermediate results can be of any object type (e.g. lists, time series).
Beispiele
Example 1: List(1;2;3).Fold
[#Plus;0] returns the sum of the numbers in the list, i.e. (((0 + 1) + 2) + 3) = 6.
Example 2: $List.Fold
[#Append;EmptyList] merges all lists, i.e. returns the same as $List.Concatenate.
For a further example, read the section The "Fold" function in the MM-Talk tips and tricks.
List.GroupBy
[equality function;selector function]→List(List)
Equality function: A two-digit function on the selector results, which should return a truth value and decide whether two list elements are to be regarded as equal. Default is #Equal.
Selector function: see Sort
Result: The GroupBy
function returns the same elements of the output list are grouped together in lists and the set of all these lists is returned in a list.
Beispiel
Example If $List is a list of securities, $List.GroupBy
[_;#ISIN] returns a list of securities lists. Each of these securities lists contains the securities for exactly one ISIN and each security from $List is available in exactly one securities list.
List.IndexOf
[Object]→Number
Result: The IndexOf
function tests whether the list contains the transferred object. It then returns the position of the first occurrence starting at 0 or the value -1 if the object does not occur.
List.IsEmpty→Boolean
Result: The IsEmpty
function tests whether the argument is empty or not. "True" is returned if the list is empty.
List.load→Object
Result: The Last
function returns the last element of the list.
List.length→number
Result: The Length
function returns the length of the list.
Object.list
[MoreObjects...]→List
Result: The List
function returns a list containing all transferred objects in the corresponding order.
n:number.MakeList→List
(number)
Result: The MakeList
function returns the list of n numbers from 0 to n-1.
Function object.map
[lists...]→list
Lists: A series of up to 5 lists corresponding to the number of arguments required by the function object.
Result: With the Map
function, the function object is applied to all list elements and the results are delivered in the form of a list. The elements of the nth list represent the nth argument of the function. The results list is just as large as the list parameters. If the list parameters have different lengths, the longest list is used as the basis; missing list elements in the other lists are filled with default values.
Beispiele
Example 1: If the variables $List1 and $List2 contain lists of numbers, the expression #Plus.Map
[$List1;$List2] makes sense. The result would be a list whose 1. Element is the sum of the first elements of list1 and list2, whose 2nd element is the sum of the second element of list2. Element is the sum of the second elements of list1 and list2 and so on.
Example 2: If $List contains a list of securities, then the expression #Name.Map
[$List] returns the list of security names. Since functions generally have a list extension (which also applies to #Name), the expression $List.Name returns the same result.
List.Nth
[n:number]→Object
Result: The Nth
function returns the nth element of the list. The count starts at 0.
List.RemoveDuplicates
[equality function;selector function]→List
Equality function: A two-digit function on the selector results, which should return a truth value and decide whether two list elements are to be regarded as equal. Default is #Equal.
Selector function: see List.Sort
Result: The RemoveDuplicates
function returns the list from which the duplicate elements have been removed. In the event of duplicate occurrences, the list elements at the front are retained and those at the back are deleted.
Beispiel
If $List is a list of securities, $List.RemoveDuplicates
[_;#ISIN] returns a list in which there is only one security object for each ISIN.
List.reverse→List
Result: The Reverse
function returns a list containing the same elements as in the argument, but in reverse order.
List.sort
[comparison function;selector function]→List
Selector function: A function object for a single-digit function that is to supply objects for the list elements according to which the list is sorted. By default, the #Object function is used here, i.e. the objects themselves are arguments for the comparison function.
Comparison function: A function object that defines the sort order, e.g. Greater or Less. The comparison function must expect two arguments of the type returned by the selector function applied to the list elements and return a Boolean.
Result: The Sort
function returns an appropriately sorted list.
Beispiel
If $List is a list of securities, $List.Sort
[#Less;#Name] returns the list of securities sorted in ascending order by security name.
List.SubList
[FromPosition:Number;ToPosition:Number]→List
Result: The SubList
function returns the sublist from position<FromPosition>up to and including position<ToPosition>.
Object.ToList→List
Result: If the object is a list, the ToList
function returns the list itself; otherwise it returns the object in a new, 1-element list. The function is used to ensure that a formula result is a list.
Object.Unique→Object
Result: If the object is a list consisting of exactly one element, or if the object is not a list, this element is delivered with the Unique
function. The function returns an error for empty lists or multi-element lists.