Sorting

Budgie supports four forms of sorting lists, all in-place.

As Numbers

For lists of type int or double, or a generic guaranteed to only ever either of those numeric types, you can sort the list with list sort numbers. It takes in the name of the list and sorts it with numeric comparisons.

JavaScript runtimes default to sorting values as strings, so this will pass in a lambda to compare them as numbers as needed.

variable : numbers { list type : int } { list new : int 20 5 15 10 }

comment line : 5, 10, 15, 20
list sort numbers : numbers

In C#:

List<int> numbers = new List<int> { 5, 15, 10 };

// 5, 10, 15, 20
numbers.Sort();

In Python:

numbers = [20, 5, 15, 10]

# 5, 10, 15, 20
numbers.sort()

As Strings

For lists of type string, you can sort the list with list sort strings. It takes in the name of the list and sorts it with string comparisons.

In C#:

In Python:

By Member Numbers

Lists of complex objects, namely class or interface instances, can be sorted by a single keyed member of those objects. list sort member numbers takes in the name of a list, the privacy type of members, a name for instances inside a comparison lambda, and the PascalCase key to look up under the instances.

Members will be compared using the built-in < operator.

In C#:

In Python:

By Member Strings

list sort member strings takes in the name of a list, the privacy type of members, a name for instances inside a comparison lambda, and the PascalCase key to look up under the instances. It's equivalent to list sort member numbers but compares members using built-in string comparisons.

In C#:

In Python:

Last updated

Was this helpful?