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(
isReversedboolean,
comparefunction
) → ObservableSortedList<T>

Constructs a new ObservableSortedList

isObservableSortedList

ObservableSortedList.isObservableSortedList(valueany) → boolean

Returns whether the value is an observable list

Observe

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

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

iterating over ObservableSortedList

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

Allows iteration over the observable map

IterateRange

ObservableSortedList:IterateRange(
startnumber,
finishnumber
) → (T) → (
(
T,
nextIndexany
) → ...any,
T?
)

Iterates over an index range

FindFirstKey

ObservableSortedList:FindFirstKey(contentT) → Symbol

Gets the first node for a given symbol

Contains

ObservableSortedList:Contains(contentT) → boolean

Returns true if the value exists

ObserveItemsBrio

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

Observes all items in the list

ObserveIndex

ObservableSortedList:ObserveIndex(indexToObservenumber) → Observable<number>

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

ObserveAtIndex

ObservableSortedList:ObserveAtIndex(indexToObservenumber) → 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(nodeSortedNode) → Observable<number>

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

GetIndexByKey

ObservableSortedList:GetIndexByKey(nodeSortedNode) → number

Gets the current index from the node

GetCount

ObservableSortedList:GetCount() → number

Gets the count of items in the list

GetList

ObservableSortedList:GetList() → {T}

Gets a list of all entries.

ObserveCount

ObservableSortedList:ObserveCount() → Observable<number>

Observes the count of the list

Add

ObservableSortedList:Add(
dataT,
observeValueObservable<Comparable> | Comparable
) → callback--

Call to remove

Adds the item to the list at the specified index

Get

ObservableSortedList:Get(indexnumber) → T?

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

RemoveByKey

ObservableSortedList:RemoveByKey(nodeSortedNode) → T

Removes the item from the list if it exists.

Destroy

ObservableSortedList:Destroy() → ()

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": 44,
                "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": 109,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the list, allocating a new list in the process.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<{ T }>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 118,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "__iter",
            "desc": "Allows iteration over the observable map",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "(T) -> ((T, nextIndex: any) -> ...any, T?)"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 131,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "IterateRange",
            "desc": "Iterates over an index range",
            "params": [
                {
                    "name": "start",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "finish",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "(T) -> ((T, nextIndex: any) -> ...any, T?)"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 146,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "FindFirstKey",
            "desc": "Gets the first node for a given symbol",
            "params": [
                {
                    "name": "content",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Symbol"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 214,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Contains",
            "desc": "Returns true if the value exists",
            "params": [
                {
                    "name": "content",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 228,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveItemsBrio",
            "desc": "Observes all items in the list",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Brio<T, Symbol>>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 239,
                "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": "indexToObserve",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 280,
                "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": "indexToObserve",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<(T, Key)>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 298,
                "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": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 318,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetIndexByKey",
            "desc": "Gets the current index from the node",
            "params": [
                {
                    "name": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 335,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetCount",
            "desc": "Gets the count of items in the list",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 345,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "GetList",
            "desc": "Gets a list of all entries.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ T }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 355,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "ObserveCount",
            "desc": "Observes the count of the list",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 367,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Add",
            "desc": "Adds the item to the list at the specified index",
            "params": [
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "observeValue",
                    "desc": "",
                    "lua_type": "Observable<Comparable> | Comparable"
                }
            ],
            "returns": [
                {
                    "desc": "Call to remove",
                    "lua_type": "callback"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 377,
                "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": "index",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 575,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "RemoveByKey",
            "desc": "Removes the item from the list if it exists.",
            "params": [
                {
                    "name": "node",
                    "desc": "",
                    "lua_type": "SortedNode"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 591,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans up the ObservableSortedList and sets the metatable to nil.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 600,
                "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": 71,
                "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": 80,
                "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": 89,
                "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
            }
        },
        {
            "name": "CountChanged",
            "desc": "Fires when the count changes",
            "lua_type": "Signal<number>",
            "readonly": true,
            "source": {
                "line": 99,
                "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": 18,
        "path": "src/observablecollection/src/Shared/SortedList/ObservableSortedList.lua"
    }
}