5
Lazy Lists
Werner edited this page 2019-07-26 22:17:41 +02:00

The LAZY* helpers are a set of defines useful for working with lists in a way that only keeps them around when they're actually needed. Lazy list operators should not be used on lists that are passed by reference as they may break the reference.

Lazy lists are useful for lowering the memory usage of list heavy objects and should generally be preferred over standard lists.

Macros

Macro Function
LAZYADD(list,item) Adds item to list. if list is null, it is created.
LAZYREMOVE(list,item) Removes item from list. If list is null, nothing is done. If list has 0 length after the item is removed, it is nulled out.
LAZYACCESS(list,index) Accesses index index of list. if list is null, null is returned. If index is a number and index is greater than list.len, null is returned. Otherwise, value at list[index] is returned.
LAZYLEN(list) Gets the length of list. If list is null, returns 0.
LAZYCLEARLIST(list) Clears list via. Cut(). If list is null, nothing is done.
UNSETEMPTY(list) If list has no length, it is nulled out. Otherwise, nothing is done.
LAZYINITLIST(list) If list is null, a new list is created and assigned to list.
LAZYSET(list,item,value) Sets a item in the list to the value. If list is null, a new list is created, the item with the specified value added and assigned to list.
LAZYPICK(list,default) Picks a item from list. If the list is empty returns the default.