| // -- start List<$E> mixins. |
| // $E is the element type. |
| |
| $if DEFINE_LENGTH_AS_NUM_ITEMS |
| // SVG Collections expose numberOfItems rather than length. |
| int get length => numberOfItems; |
| $endif |
| |
| $if DEFINE_LENGTH_SETTER |
| set length(int value) { |
| throw new UnsupportedError("Cannot resize immutable List."); |
| } |
| $endif |
| |
| $E get first { |
| if (this.length > 0) { |
| return JS('$EJS', '#[0]', this); |
| } |
| throw new StateError("No elements"); |
| } |
| |
| $E get last { |
| int len = this.length; |
| if (len > 0) { |
| return JS('$EJS', '#[#]', this, len - 1); |
| } |
| throw new StateError("No elements"); |
| } |
| |
| $E get single { |
| int len = this.length; |
| if (len == 1) { |
| return JS('$EJS', '#[0]', this); |
| } |
| if (len == 0) throw new StateError("No elements"); |
| throw new StateError("More than one element"); |
| } |
| |
| $E elementAt(int index) => this[index]; |
| // -- end List<$E> mixins. |