NamedList:
Filter:
Classes (extension) | Collections

NamedList : List : SequenceableCollection : Collection : Object
ExtensionExtension

an ordered list of items which can be accessed by index or name.
Source: NamedList.sc

Description

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

Like a List, a NamedList 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: NamedList is designed primarily for semantic clarity, to make storage as text more clearly readable for humans, and to ensure the intended order of iteration.

NamedList also does quite efficient lookup: put, at methods are reasonably fast, and direct lookup with NamedList.dict[key] or NamedList.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

NamedList.new(pairs)

NamedList.fromPairs(pairs)

create new NamedList from array of pairs

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

NamedList.fromDict(dict, names, sortFunc)

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

NamedList.newUsing(array, names)

create new NamedList from array of values and names

NamedList.fromAssocs(assocArray)

create new NamedList from array of associations:

Inherited class methods

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

.know = value

flag whether to use pseudomethods or not

.at(keyOrNum)

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

.put(keyOrNum, val)

put by key (name) or index

.add(name, item, active: true, addAction: 'replace', otherName)

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

.remove(item)

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

.removeAt(keyOrNum)

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

.addBefore(name, item, otherName)

.addAfter(name, item, otherName)

add relative to another named item

.addFirst(name, item, active: true)

.addLast(name, item, active: true)

add to top or end of list

.replace(name, item)

replace item at <name> with <item>.

.do(func)

.collect(func)

like List.do, collect

Inherited instance methods

Undocumented instance methods

.clear

.keysValuesDo(func)

.pairs