Appearance
Iterator
Inherits: LibTSMModule
Functions
Acquire
lua
function BaseType.Iterator.Acquire(func, obj, key, ...)
-> IteratorObjectAcquires an Iterator object which wraps the passed iterator function.
Parameters:
| Name | Type | Description |
|---|---|---|
func | F | The iterator function |
obj | any | The object being iterated over |
key | any | The initial key for the iterator function |
... | any | Additional arguments to pass to the iterator function |
Returns:
| Type | Description |
|---|---|
IteratorObject |
AcquireEmpty
lua
function BaseType.Iterator.AcquireEmpty()
-> IteratorObjectAcquires an Iterator object which does not produce any values.
Returns:
| Type | Description |
|---|---|
IteratorObject |
Methods
Filter
lua
function IteratorObject:Filter(func)
-> selfAdds a function to filter iterator values (happens before mapping).
Parameters:
| Name | Type | Description |
|---|---|---|
func | IteratorFilterFunc | Function which returns if a value should be provided by the iterator |
Returns:
| Type | Description |
|---|---|
self |
GetValueAndRelease
lua
function IteratorObject:GetValueAndRelease()
-> ...anyGet the next value and release the iterator.
Returns:
| Type | Description |
|---|---|
...any |
Release
lua
function IteratorObject:Release()Releases the iterator.
SetCleanupFunc
lua
function IteratorObject:SetCleanupFunc(func)
-> selfSets a function called when the iterator is released to clean up any associated context.
Parameters:
| Name | Type | Description |
|---|---|---|
func | fun(obj: any) | The cleanup function which is passed the original iterator object |
Returns:
| Type | Description |
|---|---|
self |
SetMapFunc
lua
function IteratorObject:SetMapFunc(func)
-> selfSets a function to map iterator values (happens after filtering).
Parameters:
| Name | Type | Description |
|---|---|---|
func | IteratorMapFunc | Function used to map iterator values (the key cannot be mapped and shouldn't be returned) |
Returns:
| Type | Description |
|---|---|
self |
ToJoinedValueString
lua
function IteratorObject:ToJoinedValueString(sep, sorted)
-> stringEvaluates the iterator and returns the result as a joined string of all the values.
Parameters:
| Name | Type | Description |
|---|---|---|
sep | string | The separator |
sorted | boolean | Whether or not to sort the values before concatenating it |
Returns:
| Type | Description |
|---|---|
string |