SortListUsingHandler

Typestatement
DictionaryLCB
LibraryLiveCode Builder
Syntax
sort <Target> using handler <Handler>
Associationscom.livecode.sort
Summary

Sorts Target using Handler as a comparison function.

Parameters
NameTypeDescription
Target

An expression that evaluates to a list.

Handler

A handler of type SortCompare

Example
variable sKeyIndex as Number

private handler CompareListsByElement(in pLeft as any, in pRight as any) returns Integer
   variable tLeft as Number
   variable tRight as Number
   put pLeft[sKeyIndex] into tLeft
   put pRight[sKeyIndex] into tRight

   if tLeft > tRight then
      return 1
   else if tLeft < tRight then
      return -1
   else
      return 0
   end if
end handler

-- Sort lists according to value at specified index of each list
public handler TestSortListOfLists(in pList as List, in pKeyIndex as Number) returns List
   put pKeyIndex into sKeyIndex
   sort pList using handler CompareListsByElement
   return pList
end handler
Description

SortListUsingHandler sorts a list by comparing the elements of a list according to the comparison implemented by the Handler argument.

Note: Supplying an inconsistent comparison operator to SortListUsingHandler causes undefined behavior.

Tagssorting