Skip to content

Iterator

Inherits: LibTSMModule

Functions

Acquire

lua
function BaseType.Iterator.Acquire(func, obj, key, ...)
  -> IteratorObject

Acquires an Iterator object which wraps the passed iterator function.

Parameters:

NameTypeDescription
funcFThe iterator function
objanyThe object being iterated over
keyanyThe initial key for the iterator function
...anyAdditional arguments to pass to the iterator function

Returns:

TypeDescription
IteratorObject

AcquireEmpty

lua
function BaseType.Iterator.AcquireEmpty()
  -> IteratorObject

Acquires an Iterator object which does not produce any values.

Returns:

TypeDescription
IteratorObject

Methods

Filter

lua
function IteratorObject:Filter(func)
  -> self

Adds a function to filter iterator values (happens before mapping).

Parameters:

NameTypeDescription
funcIteratorFilterFuncFunction which returns if a value should be provided by the iterator

Returns:

TypeDescription
self

GetValueAndRelease

lua
function IteratorObject:GetValueAndRelease()
  -> ...any

Get the next value and release the iterator.

Returns:

TypeDescription
...any

Release

lua
function IteratorObject:Release()

Releases the iterator.

SetCleanupFunc

lua
function IteratorObject:SetCleanupFunc(func)
  -> self

Sets a function called when the iterator is released to clean up any associated context.

Parameters:

NameTypeDescription
funcfun(obj: any)The cleanup function which is passed the original iterator object

Returns:

TypeDescription
self

SetMapFunc

lua
function IteratorObject:SetMapFunc(func)
  -> self

Sets a function to map iterator values (happens after filtering).

Parameters:

NameTypeDescription
funcIteratorMapFuncFunction used to map iterator values (the key cannot be mapped and shouldn't be returned)

Returns:

TypeDescription
self

ToJoinedValueString

lua
function IteratorObject:ToJoinedValueString(sep, sorted)
  -> string

Evaluates the iterator and returns the result as a joined string of all the values.

Parameters:

NameTypeDescription
sepstringThe separator
sortedbooleanWhether or not to sort the values before concatenating it

Returns:

TypeDescription
string