9.1 Indexables
An indexable value is one that supports […] afterward to extract an element at the index within […]. Maps, lists, arrays, sets, strings, and byte strings are all indexable, as are instances of classes that implement Indexable.
expression | ||||||||
| ||||||||
expression | ||||||||
| ||||||||
repetition | ||||||||
| ||||||||
|
With an assign_op, for a mutable indexable object (such as an array, map, set, or MutableIndexable object), the index element is assigned to the value based on the operator and rhs_expr. The expression result is #void in the case of := as assign_op.
See also use_static.
The #%index form is implicitly used when […] is used after another expression or repetition in an expression or repetition position. See also Implicit Forms.
> {"a": 1, "b": 2}["a"]
1
> {"a": 1, "b": 2} #%index ["a"]
1
An interface that a class can implement (publicly or privately) to make instances of the class work with #%index. As an annotation, Indexable matches all indexable objects, not just instances of classes that publicly implement the Indexable interface.
The interface has a single abstract method:
get(index) —
the index value is the second argument to #%index, which is normally written within […]. The result of the get method is the result of the index form.
interface | ||
An interface that extends Indexable to add support for assignment with #%index. As an annotation, MutableIndexable matches all mutable indexable objects.
The interface has one additional abstract method: