MNamedList:
Filter:
Modality-toolkit/Classes (extension) | Collections

MNamedList
ExtensionExtension

an ordered list of items which can be accessed by index or name.

Description

NOTE: NamedList is now in adclib! MNamedList is a copy of NamedList which will stay here for backwards compatibility.

Like a List, a MNamedList has an array of items which can be accessed by index. Like a dictionary, its items can also be accessed by names. Items can be added and removed and replaced by name. It also supports pseudo-object style like a dict.

Not used yet in Modality.

NOTE: MNamedList is designed primarily for semantic clarity, to make storage as text more clearly readable for humans, and to ensure the intended order of iteration.

MNamedList also does quite efficient lookup: put, at methods are reasonably fast, and direct lookup with MNamedList.dict[key] or MNamedList.array[index] is almost as fast as with Array and Event.

add, remove, removeAt methods are slower than with arrays or dicts, due to the overhead of keeping array, names and dict in sync. This design assumes that lookup will happen several orders of magnitude more often than add/remove.

Class Methods

.new

.fromPairs

create new MNamedList from array of pairs

n = MNamedList([ \a, 4, \b, 5, \c, 6 ]);

.fromDict

create new MNamedList from dict and optional ordered names or sortFunc.

.newUsing

create new MNamedList from array of values and names

.fromAssocs

create new MNamedList from array of associations:

Instance Methods

.names

the ordered list of names

n.names.postcs;

.dict

the unordered dict of items - for fast access by key

n.dict.postcs;

.know

flag whether to use pseudomethods or not

.at

put by key (name), index or collection of keys/indices

.put

put by key (name) or index

.add

add by name; if name exists, replaces item at name, else adds item to end n.add(\aaa, \xyz);

.remove

remove item from dict, array, and remove corresponding name. n.remove(\xyz);

.removeAt

remove item at key, index or list of keys and indices.

.addBefore

.addAfter

add relative to another named item

.addFirst

.addLast

add to top or end of list

.replace

replace item at <name> with <item>.

.do

.collect

like List.do, collect