TypedList

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.core" { graph [label="abjad.core"]; node [color=1]; "abjad.core.NoteHeadList.NoteHeadList" [URL="../api/abjad/utilities/../core/NoteHeadList.html#abjad.core.NoteHeadList.NoteHeadList", label="Note\nHead\nList", target=_top]; } subgraph "cluster_abjad.markups" { graph [label="abjad.markups"]; node [color=2]; "abjad.markups.MarkupList" [URL="../api/abjad/utilities/../markups.html#abjad.markups.MarkupList", label="Markup\nList", target=_top]; } subgraph "cluster_abjad.meter" { graph [label="abjad.meter"]; node [color=3]; "abjad.meter.MeterList" [URL="../api/abjad/utilities/../meter.html#abjad.meter.MeterList", label="Meter\nList", target=_top]; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=4]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/utilities/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph "cluster_abjad.timespans" { graph [label="abjad.timespans"]; node [color=5]; "abjad.timespans.CompoundInequality.CompoundInequality" [URL="../api/abjad/utilities/../timespans/CompoundInequality.html#abjad.timespans.CompoundInequality.CompoundInequality", label="Compound\nInequality", target=_top]; "abjad.timespans.TimespanList.TimespanList" [URL="../api/abjad/utilities/../timespans/TimespanList.html#abjad.timespans.TimespanList.TimespanList", label="Timespan\nList", target=_top]; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=6]; "abjad.utilities.TypedCollection.TypedCollection" [URL="../api/abjad/utilities/TypedCollection.html#abjad.utilities.TypedCollection.TypedCollection", label="Typed\nCollection", shape=oval, style=bold, target=_top]; "abjad.utilities.TypedList.TypedList" [URL="../api/abjad/utilities/TypedList.html#abjad.utilities.TypedList.TypedList", color=black, fontcolor=white, label="Typed\nList", target=_top]; "abjad.utilities.TypedCollection.TypedCollection" -> "abjad.utilities.TypedList.TypedList"; } subgraph cluster_builtins { graph [label=builtins]; node [color=7]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_collections.abc" { graph [label="collections.abc"]; node [color=8]; "collections.abc.Collection" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Collection", label=Collection, shape=oval, style=bold, target=_top]; "collections.abc.Container" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Container", label=Container, shape=oval, style=bold, target=_top]; "collections.abc.Iterable" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Iterable", label=Iterable, shape=oval, style=bold, target=_top]; "collections.abc.MutableSequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.MutableSequence", label="Mutable\nSequence", shape=oval, style=bold, target=_top]; "collections.abc.Reversible" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Reversible", label=Reversible, shape=oval, style=bold, target=_top]; "collections.abc.Sequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sequence", label=Sequence, shape=oval, style=bold, target=_top]; "collections.abc.Sized" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sized", label=Sized, shape=oval, style=bold, target=_top]; "collections.abc.Collection" -> "collections.abc.Sequence"; "collections.abc.Container" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Reversible"; "collections.abc.Reversible" -> "collections.abc.Sequence"; "collections.abc.Sequence" -> "collections.abc.MutableSequence"; "collections.abc.Sized" -> "collections.abc.Collection"; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.utilities.TypedCollection.TypedCollection"; "abjad.utilities.TypedList.TypedList" -> "abjad.core.NoteHeadList.NoteHeadList"; "abjad.utilities.TypedList.TypedList" -> "abjad.markups.MarkupList"; "abjad.utilities.TypedList.TypedList" -> "abjad.meter.MeterList"; "abjad.utilities.TypedList.TypedList" -> "abjad.timespans.CompoundInequality.CompoundInequality"; "abjad.utilities.TypedList.TypedList" -> "abjad.timespans.TimespanList.TimespanList"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "collections.abc.Container"; "builtins.object" -> "collections.abc.Iterable"; "builtins.object" -> "collections.abc.Sized"; "collections.abc.MutableSequence" -> "abjad.utilities.TypedList.TypedList"; }

class abjad.utilities.TypedList.TypedList(items=None, item_class=None, keep_sorted=False)

Typed list.

No item coercion:

>>> list_ = abjad.TypedList()
>>> list_.append(23)
>>> list_.append('foo')
>>> list_.append(False)
>>> list_.append((1, 2, 3))
>>> list_.append(3.14159)
>>> abjad.f(list_)
abjad.TypedList(
    [
        23,
        'foo',
        False,
        (1, 2, 3),
        3.14159,
        ]
    )

Named pitch item coercion:

>>> pitch_list = abjad.TypedList(
...     item_class=abjad.NamedPitch,
...     )
>>> pitch_list.append(0)
>>> pitch_list.append("d'")
>>> pitch_list.append(('e', 4))
>>> pitch_list.append(abjad.NamedPitch("f'"))
>>> abjad.f(pitch_list)
abjad.TypedList(
    [
        abjad.NamedPitch("c'"),
        abjad.NamedPitch("d'"),
        abjad.NamedPitch("e'"),
        abjad.NamedPitch("f'"),
        ],
    item_class=abjad.NamedPitch,
    )

Ordered collection with optional item coercion.

Implements the list interface.


Attributes Summary

__delitem__ Aliases list.__delitem__().
__getitem__ Gets item or slice identified by argument.
__iadd__ Adds argument in place to typed list.
__reversed__ Aliases list.__reversed__().
__setitem__ Sets item i equal to argument.
append Appends item to typed list.
count Gets count of item in typed list.
extend Extends typed list with items.
index Gets index of item in typed list.
insert Insert item into typed list.
keep_sorted Is true when typed list keeps items sorted.
pop Pops item i from typed list.
remove Removes item from typed list.
reverse Reverses items in typed list.
sort Sorts items in typed list.

Special methods

(TypedCollection).__contains__(item)

Is true when typed collection contains item.

Returns true or false.

__delitem__(i)

Aliases list.__delitem__().

Returns none.

(TypedCollection).__eq__(argument)

Is true when argument is a typed collection with items that compare equal to those of this typed collection.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

__getitem__(argument)

Gets item or slice identified by argument.

Returns item or slice.

(TypedCollection).__hash__()

Hashes typed collection.

Redefined in tandem with __eq__.

__iadd__(argument)

Adds argument in place to typed list.

>>> dynamic_list = abjad.TypedList(item_class=abjad.Dynamic)
>>> dynamic_list.append('ppp')
>>> dynamic_list += ['p', 'mp', 'mf', 'fff']
>>> abjad.f(dynamic_list)
abjad.TypedList(
    [
        abjad.Dynamic('ppp'),
        abjad.Dynamic('p'),
        abjad.Dynamic('mp'),
        abjad.Dynamic('mf'),
        abjad.Dynamic('fff'),
        ],
    item_class=abjad.Dynamic,
    )

Returns typed list.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

__reversed__()

Aliases list.__reversed__().

Returns generator.

__setitem__(i, argument)

Sets item i equal to argument.

Sets item:

>>> pitch_list = abjad.TypedList(
...     item_class=abjad.NamedPitch,
...     )
>>> pitch_list.append(0)
>>> pitch_list.append("d'")
>>> pitch_list.append(('e', 4))
>>> pitch_list.append(abjad.NamedPitch("f'"))
>>> pitch_list[-1] = 'gqs,'
>>> abjad.f(pitch_list)
abjad.TypedList(
    [
        abjad.NamedPitch("c'"),
        abjad.NamedPitch("d'"),
        abjad.NamedPitch("e'"),
        abjad.NamedPitch('gqs,'),
        ],
    item_class=abjad.NamedPitch,
    )

Sets slice:

>>> pitch_list[-1:] = ["f'", "g'", "a'", "b'", "c''"]
>>> abjad.f(pitch_list)
abjad.TypedList(
    [
        abjad.NamedPitch("c'"),
        abjad.NamedPitch("d'"),
        abjad.NamedPitch("e'"),
        abjad.NamedPitch("f'"),
        abjad.NamedPitch("g'"),
        abjad.NamedPitch("a'"),
        abjad.NamedPitch("b'"),
        abjad.NamedPitch("c''"),
        ],
    item_class=abjad.NamedPitch,
    )

Returns none.


Methods

append(item)

Appends item to typed list.

>>> integer_list = abjad.TypedList(item_class=int)
>>> integer_list.append('1')
>>> integer_list.append(2)
>>> integer_list.append(3.4)
>>> integer_list[:]
[1, 2, 3]

Returns none.

(MutableSequence).clear() → None -- remove all items from S
count(item)

Gets count of item in typed list.

>>> integer_list = abjad.TypedList(item_class=int)
>>> integer_list.extend([0, 0., '0', 99])
>>> integer_list.count(0)
3
>>> integer_list.count(1)
0
>>> integer_list.count(99)
1

Returns nonnegative integer.

extend(items)

Extends typed list with items.

>>> integer_list = abjad.TypedList(item_class=int)
>>> integer_list.extend(['0', 1.0, 2, 3.14159])
>>> integer_list
TypedList([0, 1, 2, 3], item_class=int)

Returns none.

index(item)

Gets index of item in typed list.

>>> pitch_list = abjad.TypedList(
...     item_class=abjad.NamedPitch,
...     )
>>> pitch_list.extend(['cqf', "as'", 'b,', 'dss'])
>>> pitch_list.index(abjad.NamedPitch('cqf'))
0
>>> pitch_list.index(abjad.NamedPitch("as'"))
1
>>> pitch_list.index('b,')
2
>>> pitch_list.index('dss')
3

Returns nonnegative integer.

insert(i, item)

Insert item into typed list.

Inserts into typed list.

>>> integer_list = abjad.TypedList(item_class=int)
>>> integer_list.extend(['1', 2, 4.3])
>>> integer_list
TypedList([1, 2, 4], item_class=int)
>>> integer_list.insert(0, '0')
>>> integer_list
TypedList([0, 1, 2, 4], item_class=int)
>>> integer_list.insert(1, '9')
>>> integer_list
TypedList([0, 9, 1, 2, 4], item_class=int)

Returns none.

pop(i=-1)

Pops item i from typed list.

Returns item.

remove(item)

Removes item from typed list.

>>> integer_list = abjad.TypedList(item_class=int)
>>> integer_list.extend(('0', 1.0, 2, 3.14159))
>>> integer_list[:]
[0, 1, 2, 3]
>>> integer_list.remove('1')
>>> integer_list[:]
[0, 2, 3]

Returns none.

reverse()

Reverses items in typed list.

sort(cmp=None, key=None, reverse=False)

Sorts items in typed list.


Read/write properties

keep_sorted

Is true when typed list keeps items sorted.

Defaults to none.

Set to true, false or none.

Returns true, false or none.


Read-only properties

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

(TypedCollection).items

Gets items in collection.

Returns list.