Skip to main content

ObservableSortedList

A list that can be observed for blend and other components and maintains sorting order.

This allows you to observe both an index, observe a value at an index, and more.

This class is a red-black binary sorted tree. Unlike previous iterations of this class, we can add values in log(n) time, and remove in log(n) time, and it uses less memory.

Previously we'd use O(n^2) processing time when constructing this class.

We reuse the node itself as the indexing key.

This class always prefers to add equivalent elements to the end of the list if they're not in the list. Otherwise it prefers minimal movement.

Properties​

ItemAdded​

This item is read only and cannot be modified. Read Only
ObservableSortedList.ItemAdded: Signal<T,number,Symbol>

Fires when an item is added

ItemRemoved​

This item is read only and cannot be modified. Read Only
ObservableSortedList.ItemRemoved: Signal<T,Symbol>

Fires when an item is removed.

OrderChanged​

This item is read only and cannot be modified. Read Only
ObservableSortedList.OrderChanged: Signal

Fires when the order could have changed

CountChanged​

This item is read only and cannot be modified. Read Only
ObservableSortedList.CountChanged: Signal<number>

Fires when the count changes

Functions​

new​

ObservableSortedList.new(
isReversed: boolean,
compare: function
) → ObservableSortedList<T>

Constructs a new ObservableSortedList

isObservableSortedList​

ObservableSortedList.isObservableSortedList(value: any) → boolean

Returns whether the value is an observable list

Observe​

ObservableSortedList.Observe(self: ObservableSortedList<T>) → Observable<{T}>

Observes the list, allocating a new list in the process.

iterating over ObservableSortedList​

for  (T) → (
(
T,
nextIndex: any
) → ...any,
T?
) 
 in  ObservableSortedList  do

Allows iteration over the observable map

IterateRange​

ObservableSortedList.IterateRange(
start: number,
finish: number
) → (T) → (
(
T,
nextIndex: any
) → ...any,
T?
)

Iterates over an index range

FindFirstKey​

ObservableSortedList.FindFirstKey(
content: T
) → Symbol

Gets the first node for a given symbol

Contains​

ObservableSortedList.Contains(
content: T
) → boolean

Returns true if the value exists

ObserveItemsBrio​

ObservableSortedList.ObserveItemsBrio(self: ObservableSortedList<T>) → Observable<Brio<T,Symbol>>

Observes all items in the list

ObserveIndex​

ObservableSortedList.ObserveIndex(
indexToObserve: number
) → Observable<number>

Observes the index as it changes, until the entry at the existing index is removed.

ObserveAtIndex​

ObservableSortedList.ObserveAtIndex(
indexToObserve: number
) → Observable<(
T,
Key
)>

Observes the current value at a given index. This can be useful for observing the first entry, or matching stuff up to a given slot.

ObserveIndexByKey​

ObservableSortedList.ObserveIndexByKey() → Observable<number>

Observes the index as it changes, until the entry at the existing node is removed.

GetIndexByKey​

ObservableSortedList.GetIndexByKey() → number

Gets the current index from the node

GetCount​

ObservableSortedList.GetCount(self: ObservableSortedList<T>) → number

Gets the count of items in the list

GetList​

ObservableSortedList.GetList(self: ObservableSortedList<T>) → {T}

Gets a list of all entries.

ObserveCount​

ObservableSortedList.ObserveCount(self: ObservableSortedList<T>) → Observable<number>

Observes the count of the list

Add​

ObservableSortedList.Add(
data: T,
observeValue: Observable<Comparable> | Comparable
) → callback--

Call to remove

Adds the item to the list at the specified index

Get​

ObservableSortedList.Get(
index: number
) → T?

Gets the current item at the index, or nil if it is not defined.

RemoveByKey​

ObservableSortedList.RemoveByKey() → T

Removes the item from the list if it exists.

Destroy​

ObservableSortedList.Destroy(self: ObservableSortedList<T>) → ()

Cleans up the ObservableSortedList and sets the metatable to nil.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new ObservableSortedList",
            "params": [
                {
                    "name": "isReversed",
                    "desc": "",
                    "lua_type": "boolean"
                },
                {
                    "name": "compare",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 71,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "isObservableSortedList",
            "desc": "Returns whether the value is an observable list",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 141,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the list, allocating a new list in the process.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<{ T }>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 150,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "__iter",
            "desc": "Allows iteration over the observable map",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "(T) -> ((T, nextIndex: any) -> ...any, T?)"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 163,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "IterateRange",
            "desc": "Iterates over an index range",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "start",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "finish",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "(T) -> ((T, nextIndex: any) -> ...any, T?)"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 178,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "FindFirstKey",
            "desc": "Gets the first node for a given symbol",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "content",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Symbol"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 259,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Contains",
            "desc": "Returns true if the value exists",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "content",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 273,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveItemsBrio",
            "desc": "Observes all items in the list",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>\n"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Brio<T, Symbol>>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 284,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveIndex",
            "desc": "Observes the index as it changes, until the entry at the existing\nindex is removed.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "indexToObserve",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 334,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveAtIndex",
            "desc": "Observes the current value at a given index. This can be useful for observing\nthe first entry, or matching stuff up to a given slot.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "indexToObserve",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<(T, Key)>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 360,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveIndexByKey",
            "desc": "Observes the index as it changes, until the entry at the existing\nnode is removed.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 384,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetIndexByKey",
            "desc": "Gets the current index from the node",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 404,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetCount",
            "desc": "Gets the count of items in the list",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 414,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetList",
            "desc": "Gets a list of all entries.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ T }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 424,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveCount",
            "desc": "Observes the count of the list",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 436,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Add",
            "desc": "Adds the item to the list at the specified index",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "observeValue",
                    "desc": "",
                    "lua_type": "Observable<Comparable> | Comparable"
                }
            ],
            "returns": [
                {
                    "desc": "Call to remove",
                    "lua_type": "callback"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 446,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Get",
            "desc": "Gets the current item at the index, or nil if it is not defined.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "index",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 701,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "RemoveByKey",
            "desc": "Removes the item from the list if it exists.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                },
                {
                    "name": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 717,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans up the ObservableSortedList and sets the metatable to nil.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ObservableSortedList<T>"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 726,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "ItemAdded",
            "desc": "Fires when an item is added",
            "lua_type": "Signal<T, number, Symbol>",
            "readonly": true,
            "source": {
                "line": 100,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ItemRemoved",
            "desc": "Fires when an item is removed.",
            "lua_type": "Signal<T, Symbol>",
            "readonly": true,
            "source": {
                "line": 109,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "OrderChanged",
            "desc": "Fires when the order could have changed",
            "lua_type": "Signal",
            "readonly": true,
            "source": {
                "line": 118,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "CountChanged",
            "desc": "Fires when the count changes",
            "lua_type": "Signal<number>",
            "readonly": true,
            "source": {
                "line": 131,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        }
    ],
    "types": [],
    "name": "ObservableSortedList",
    "desc": "A list that can be observed for blend and other components and maintains sorting order.\n\nThis allows you to observe both an index, observe a value at an index, and more.\n\nThis class is a red-black binary sorted tree. Unlike previous iterations of this class, we can add\nvalues in log(n) time, and remove in log(n) time, and it uses less memory.\n\nPreviously we'd use O(n^2) processing time when constructing this class.\n\nWe reuse the node itself as the indexing key.\n\nThis class always prefers to add equivalent elements to the end of the list if they're not in the list.\nOtherwise it prefers minimal movement.",
    "source": {
        "line": 19,
        "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
    }
}